Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 23 | import android.annotation.SdkConstant; |
| 24 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 26 | import android.annotation.TestApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 27 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 28 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 29 | import android.app.Activity; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 30 | import android.app.IServiceConnection; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 31 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 32 | import android.content.ComponentName; |
| 33 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 34 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 35 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 36 | import android.content.ServiceConnection; |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 37 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 38 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 39 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 40 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 41 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 42 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 43 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 44 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 45 | import android.os.Bundle; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 46 | import android.os.Parcelable; |
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> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 155 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 156 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 157 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 158 | * <p>When managed provisioning has completed, broadcasts are sent to the application specified |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 159 | * in the provisioning intent. The |
| 160 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 161 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 162 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 163 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 164 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 165 | * completed, along with the above broadcast, activity intent |
| 166 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in |
| 167 | * the provisioning intent. |
| 168 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 169 | * <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] | 170 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 171 | * |
| 172 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 173 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 174 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 175 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 176 | * 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] | 177 | */ |
| 178 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 179 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 180 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 181 | |
| 182 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 183 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 184 | * |
| 185 | * <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] | 186 | * 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] | 187 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 188 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 189 | * allowed. |
| 190 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 191 | * <p>The intent contains the following extras: |
| 192 | * <ul> |
| 193 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 194 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 195 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 196 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 197 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 198 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 199 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 200 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 201 | * |
| 202 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 203 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 204 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 205 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 206 | * 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] | 207 | * |
| 208 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 209 | */ |
| 210 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 211 | public static final String ACTION_PROVISION_MANAGED_USER |
| 212 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 213 | |
| 214 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 215 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 216 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 217 | * |
| 218 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 219 | * A device owner has full control over the device. The device owner can not be modified by the |
| 220 | * user. |
| 221 | * |
| 222 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 223 | * employee or client. |
| 224 | * |
| 225 | * <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] | 226 | * It is possible to check if provisioning is allowed or not by querying the method |
| 227 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 228 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 229 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 230 | * <ul> |
| 231 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 232 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 233 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 234 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 235 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 236 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 237 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 238 | * </ul> |
| 239 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 240 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 241 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 242 | * device owner. |
| 243 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 244 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 245 | * completed, along with the above broadcast, activity intent |
| 246 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 247 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 248 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 249 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 250 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 251 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 252 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 253 | * 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] | 254 | */ |
| 255 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 256 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 257 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 258 | |
| 259 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 260 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 261 | * |
| 262 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 263 | * the device. A device owner has full control over the device. The device owner can not be |
| 264 | * modified by the user and the only way of resetting the device is via factory reset. |
| 265 | * |
| 266 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 267 | * employee or client. |
| 268 | * |
| 269 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 270 | * |
| 271 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 272 | * by a privileged app with the permission |
| 273 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 274 | * |
| 275 | * <p>The provisioning intent contains the following properties: |
| 276 | * <ul> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 279 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 280 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 281 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 282 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 283 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 284 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 285 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 286 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 287 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 288 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 289 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 290 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 291 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 292 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 293 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 294 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 295 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 296 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 297 | * |
| 298 | * @hide |
| 299 | */ |
| 300 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 301 | @SystemApi |
| 302 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 303 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 304 | |
| 305 | /** |
| 306 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 307 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 308 | * |
| 309 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 310 | * management state that is distinct from that reached by |
| 311 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 312 | * user, and only has control over device-wide policies, not individual users and their data. |
| 313 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 314 | * this form of device management. |
| 315 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 316 | * <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] | 317 | * A device owner has full control over the device. The device owner can not be modified by the |
| 318 | * user. |
| 319 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 320 | * <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] | 321 | * employee or client. |
| 322 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 323 | * <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] | 324 | * It is possible to check if provisioning is allowed or not by querying the method |
| 325 | * {@link #isProvisioningAllowed(String)}. |
| 326 | * |
| 327 | * <p>The intent contains the following extras: |
| 328 | * <ul> |
| 329 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 330 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 331 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 332 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 333 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 334 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 335 | * </ul> |
| 336 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 337 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 338 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 339 | * device owner. |
| 340 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 341 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 342 | * completed, along with the above broadcast, activity intent |
| 343 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 344 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 345 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 346 | * |
| 347 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 348 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 349 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 350 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 351 | * |
| 352 | * @hide |
| 353 | */ |
| 354 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 355 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 356 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 357 | |
| 358 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 359 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 360 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 361 | * <ul> |
| 362 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 363 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 364 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 365 | * </ul> |
| 366 | * |
| 367 | * @hide |
| 368 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 369 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 370 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 371 | public static final String ACTION_PROVISION_FINALIZATION |
| 372 | = "android.app.action.PROVISION_FINALIZATION"; |
| 373 | |
| 374 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 375 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 376 | * |
| 377 | * @hide |
| 378 | */ |
| 379 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 380 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 384 | * |
| 385 | * @hide |
| 386 | */ |
| 387 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 388 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 389 | |
| 390 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 391 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 392 | * |
| 393 | * @hide |
| 394 | */ |
| 395 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 396 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 397 | |
| 398 | /** |
| 399 | * Extra for shared bugreport's SHA-256 hash. |
| 400 | * |
| 401 | * @hide |
| 402 | */ |
| 403 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 404 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 405 | |
| 406 | /** |
| 407 | * Extra for remote bugreport notification shown type. |
| 408 | * |
| 409 | * @hide |
| 410 | */ |
| 411 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 412 | "android.app.extra.bugreport_notification_type"; |
| 413 | |
| 414 | /** |
| 415 | * Notification type for a started remote bugreport flow. |
| 416 | * |
| 417 | * @hide |
| 418 | */ |
| 419 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 420 | |
| 421 | /** |
| 422 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 423 | * being taken. |
| 424 | * |
| 425 | * @hide |
| 426 | */ |
| 427 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 428 | |
| 429 | /** |
| 430 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 431 | * |
| 432 | * @hide |
| 433 | */ |
| 434 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 435 | |
| 436 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 437 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 438 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 439 | * |
| 440 | * @hide |
| 441 | */ |
| 442 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 443 | |
| 444 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 445 | * 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] | 446 | * allows a mobile device management application or NFC programmer application which starts |
| 447 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 448 | * <p> |
| 449 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 450 | * sends the intent to pass data to itself on the newly created profile. |
| 451 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 452 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 453 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 454 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 455 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 456 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 457 | * management application after provisioning. |
| 458 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 459 | * <p> |
| 460 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 461 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 462 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 463 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 464 | */ |
| 465 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 466 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 467 | |
| 468 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 469 | * A String extra holding the package name of the mobile device management application that |
| 470 | * will be set as the profile owner or device owner. |
| 471 | * |
| 472 | * <p>If an application starts provisioning directly via an intent with action |
| 473 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 474 | * application that started provisioning. The package will be set as profile owner in that case. |
| 475 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 476 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 477 | * 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] | 478 | * |
| 479 | * <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] | 480 | * 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] | 481 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 482 | * @see DeviceAdminReceiver |
| 483 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a8 | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 484 | * supported, but only if there is only one device admin receiver in the package that requires |
| 485 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 486 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 487 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 488 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 489 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 490 | |
| 491 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 492 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 493 | * application that will be set as the profile owner or device owner and active admin. |
| 494 | * |
| 495 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 496 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 497 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 498 | * 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] | 499 | * |
| 500 | * <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] | 501 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 502 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 503 | * {@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] | 504 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 505 | * |
| 506 | * @see DeviceAdminReceiver |
| 507 | */ |
| 508 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 509 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 510 | |
| 511 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 512 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 513 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 514 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 515 | * |
| 516 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 517 | */ |
| 518 | |
| 519 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 520 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 521 | |
| 522 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 523 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 524 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 525 | * the account will not be removed from the primary user after it is migrated to the newly |
| 526 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 527 | * |
| 528 | * <p> Defaults to {@code false} |
| 529 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 530 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 531 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 532 | */ |
| 533 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 534 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 535 | |
| 536 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 537 | * A String extra that, holds the email address of the account which a managed profile is |
| 538 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 539 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 540 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 541 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 542 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 543 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 544 | * contains this extra, it is forwarded in the |
| 545 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 546 | * device management application that was set as the profile owner during provisioning. |
| 547 | * 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] | 548 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 549 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 550 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 551 | |
| 552 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 553 | * A integer extra indicating the predominant color to show during the provisioning. |
| 554 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 555 | * |
| 556 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 557 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 558 | */ |
| 559 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 560 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 561 | |
| 562 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 563 | * 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] | 564 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 565 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 566 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 567 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 568 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 569 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 570 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 571 | |
| 572 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 573 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 574 | * will be set to. |
| 575 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 576 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 577 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 578 | */ |
| 579 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 580 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 581 | |
| 582 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 583 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 584 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 585 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 586 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 587 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 588 | */ |
| 589 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 590 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 591 | |
| 592 | /** |
| 593 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 594 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 595 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 596 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 597 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 598 | */ |
| 599 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 600 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 601 | |
| 602 | /** |
| 603 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 604 | * owner provisioning for downloading the mobile device management application. |
| 605 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 606 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 607 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 608 | */ |
| 609 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 610 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 611 | |
| 612 | /** |
| 613 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 614 | * is hidden or not. |
| 615 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 616 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 617 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 618 | */ |
| 619 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 620 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 621 | |
| 622 | /** |
| 623 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 624 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 625 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 626 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 627 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 628 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 629 | */ |
| 630 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 631 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 632 | |
| 633 | /** |
| 634 | * A String extra holding the password of the wifi network in |
| 635 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 636 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 637 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 638 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 639 | */ |
| 640 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 641 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 642 | |
| 643 | /** |
| 644 | * A String extra holding the proxy host for the wifi network in |
| 645 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 646 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 647 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 648 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 649 | */ |
| 650 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 651 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 652 | |
| 653 | /** |
| 654 | * An int extra holding the proxy port for the wifi network in |
| 655 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 656 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 657 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 658 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 659 | */ |
| 660 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 661 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 662 | |
| 663 | /** |
| 664 | * A String extra holding the proxy bypass for the wifi network in |
| 665 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 666 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 667 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 668 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 669 | */ |
| 670 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 671 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 672 | |
| 673 | /** |
| 674 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 675 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 676 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 677 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 678 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 679 | */ |
| 680 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 681 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 682 | |
| 683 | /** |
| 684 | * A String extra holding a url that specifies the download location of the device admin |
| 685 | * package. When not provided it is assumed that the device admin package is already installed. |
| 686 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 687 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 688 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 689 | */ |
| 690 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 691 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 692 | |
| 693 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 694 | * A String extra holding the localized name of the organization under management. |
| 695 | * |
| 696 | * The name is displayed only during provisioning. |
| 697 | * |
| 698 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 699 | * |
| 700 | * @hide |
| 701 | */ |
| 702 | @SystemApi |
| 703 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 704 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 705 | |
| 706 | /** |
| 707 | * A String extra holding a url to the website of the device's provider. The website can be |
| 708 | * opened in a browser during provisioning. |
| 709 | * |
| 710 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 711 | * |
| 712 | * @hide |
| 713 | */ |
| 714 | @SystemApi |
| 715 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 716 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 717 | |
| 718 | /** |
| 719 | * A String extra holding the localized name of the device admin package. It should be the same |
| 720 | * as the app label of the package. |
| 721 | * |
| 722 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 723 | * |
| 724 | * @hide |
| 725 | */ |
| 726 | @SystemApi |
| 727 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 728 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 729 | |
| 730 | /** |
| 731 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 732 | * shown during the provisioning. |
| 733 | * <h5>The following URI schemes are accepted:</h5> |
| 734 | * <ul> |
| 735 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 736 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 737 | * </ul> |
| 738 | * |
| 739 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 740 | * pixel density for the device. |
| 741 | * |
| 742 | * <p> If a content: URI is passed, the intent should have the flag |
| 743 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 744 | * {@link android.content.ClipData} of the intent too. |
| 745 | * |
| 746 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 747 | * |
| 748 | * @hide |
| 749 | */ |
| 750 | @SystemApi |
| 751 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 752 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 753 | |
| 754 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 755 | * An int extra holding a minimum required version code for the device admin package. If the |
| 756 | * device admin is already installed on the device, it will only be re-downloaded from |
| 757 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 758 | * installed package is less than this version code. |
| 759 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 760 | * <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] | 761 | * provisioning via an NFC bump. |
| 762 | */ |
| 763 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 764 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 765 | |
| 766 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 767 | * A String extra holding a http cookie header which should be used in the http request to the |
| 768 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 769 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 770 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 771 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 772 | */ |
| 773 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 774 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 775 | |
| 776 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 777 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 778 | * the file at download location specified in |
| 779 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 780 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 781 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 782 | * 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] | 783 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 784 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 785 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 786 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 787 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 788 | * |
| 789 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 790 | * 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] | 791 | * 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] | 792 | * 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] | 793 | */ |
| 794 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 795 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 796 | |
| 797 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 798 | * 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] | 799 | * android package archive at the download location specified in {@link |
| 800 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 801 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 802 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 803 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 804 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 805 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 806 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 807 | * 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] | 808 | * the download location. If the checksum does not match an error will be shown to the user and |
| 809 | * the user will be asked to factory reset the device. |
| 810 | * |
| 811 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 812 | * provisioning via an NFC bump. |
| 813 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 814 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 815 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 816 | |
| 817 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 818 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 819 | * has completed successfully. |
| 820 | * |
| 821 | * <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] | 822 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 823 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 824 | * <p>This intent will contain the following extras |
| 825 | * <ul> |
| 826 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 827 | * profile.</li> |
| 828 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 829 | * be migrated at provisioning time, if any.</li> |
| 830 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 831 | */ |
| 832 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 833 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 834 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 835 | |
| 836 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 837 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 838 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 839 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 840 | * delivered faster as it's an activity intent. |
| 841 | * |
| 842 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 843 | * the device owner case the profile is the primary user. |
| 844 | * |
| 845 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 846 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 847 | */ |
| 848 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 849 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 850 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 851 | |
| 852 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 853 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 854 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 855 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 856 | * <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] | 857 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 858 | * |
| 859 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 860 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 861 | */ |
| 862 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 863 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 864 | |
| 865 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 866 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 867 | * provisioning. If this extra is not passed, a default image will be shown. |
| 868 | * <h5>The following URI schemes are accepted:</h5> |
| 869 | * <ul> |
| 870 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 871 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 872 | * </ul> |
| 873 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 874 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 875 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 876 | * |
| 877 | * <p> If a content: URI is passed, the intent should have the flag |
| 878 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 879 | * {@link android.content.ClipData} of the intent too. |
| 880 | * |
| 881 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 882 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 883 | */ |
| 884 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 885 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 886 | |
| 887 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 888 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 889 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 890 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 891 | * content. |
| 892 | * |
| 893 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 894 | * management application (MDM), and one disclaimer from the organization. |
| 895 | * |
| 896 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 897 | * |
| 898 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 899 | * |
| 900 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 901 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 902 | */ |
| 903 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 904 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 905 | |
| 906 | /** |
| 907 | * A String extra of localized disclaimer header. |
| 908 | * |
| 909 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 910 | * or the organization name. |
| 911 | * |
| 912 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 913 | * |
| 914 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 915 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 916 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 917 | * |
| 918 | * <pre> |
| 919 | * <meta-data |
| 920 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 921 | * android:resource="@string/disclaimer_header" |
| 922 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 923 | */ |
| 924 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 925 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 926 | |
| 927 | /** |
| 928 | * A {@link Uri} extra pointing to disclaimer content. |
| 929 | * |
| 930 | * <h5>The following URI schemes are accepted:</h5> |
| 931 | * <ul> |
| 932 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 933 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 934 | * </ul> |
| 935 | * |
| 936 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 937 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 938 | * {@link android.widget.TextView}. |
| 939 | * |
| 940 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 941 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 942 | * {@link android.content.ClipData} of the intent too. |
| 943 | * |
| 944 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 945 | * |
| 946 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 947 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 948 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 949 | * |
| 950 | * <pre> |
| 951 | * <meta-data |
| 952 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 953 | * android:resource="@string/disclaimer_content" |
| 954 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 955 | */ |
| 956 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 957 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 958 | |
| 959 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 960 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 961 | * during setup-wizard. |
| 962 | * |
| 963 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 964 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 965 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 966 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 967 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 968 | * |
| 969 | * @hide |
| 970 | */ |
| 971 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 972 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 973 | |
| 974 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 975 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 976 | * skipped. If unspecified, defaults to {@code false}. |
| 977 | * |
| 978 | * It can only be used by an existing device owner trying to create a managed profile via |
| 979 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 980 | */ |
| 981 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 982 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 983 | |
| 984 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 985 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 986 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 987 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 988 | * A device owner has full control over the device. The device owner can not be modified by the |
| 989 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 990 | * reset. |
| 991 | * |
| 992 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 993 | * employee or client. |
| 994 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 995 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 996 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 997 | * <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] | 998 | * contains the following properties: |
| 999 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1000 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 1001 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 1002 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1003 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1004 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1005 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1006 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1007 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1008 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1009 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1010 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1011 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1012 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1013 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1014 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1015 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1016 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1017 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1018 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1019 | * 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] | 1020 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1021 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1022 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1023 | */ |
| 1024 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1025 | = "application/com.android.managedprovisioning"; |
| 1026 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1027 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1028 | * Activity action: ask the user to add a new device administrator to the system. |
| 1029 | * The desired policy is the ComponentName of the policy in the |
| 1030 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1031 | * bring the user through adding the device administrator to the system (or |
| 1032 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1033 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1034 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1035 | * field to provide the user with additional explanation (in addition |
| 1036 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1037 | * |
| 1038 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1039 | * user intervention). However, if your administrator has been updated and is requesting |
| 1040 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1041 | * 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] | 1042 | */ |
| 1043 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1044 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1045 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1046 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1047 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1048 | * @hide |
| 1049 | * 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] | 1050 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1051 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1052 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1053 | * 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] | 1054 | * to remotely control restrictions on the user. |
| 1055 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1056 | * <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] | 1057 | * result of whether or not the user approved the action. If approved, the result will |
| 1058 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1059 | * as a profile owner. |
| 1060 | * |
| 1061 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1062 | * field to provide the user with additional explanation (in addition |
| 1063 | * to your component's description) about what is being added. |
| 1064 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1065 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1066 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1067 | */ |
| 1068 | @SystemApi |
| 1069 | public static final String ACTION_SET_PROFILE_OWNER |
| 1070 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1071 | |
| 1072 | /** |
| 1073 | * @hide |
| 1074 | * Name of the profile owner admin that controls the user. |
| 1075 | */ |
| 1076 | @SystemApi |
| 1077 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1078 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1079 | |
| 1080 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1081 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1082 | * 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] | 1083 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1084 | * @hide |
| 1085 | */ |
| 1086 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1087 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1088 | |
| 1089 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1090 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1091 | * |
| 1092 | * This broadcast is sent only to the primary user. |
| 1093 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1094 | */ |
| 1095 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1096 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1097 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1098 | |
| 1099 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1100 | * The ComponentName of the administrator component. |
| 1101 | * |
| 1102 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1103 | */ |
| 1104 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1105 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1106 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1107 | * An optional CharSequence providing additional explanation for why the |
| 1108 | * admin is being added. |
| 1109 | * |
| 1110 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1111 | */ |
| 1112 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1113 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1114 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1115 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1116 | * {@link #createAdminSupportIntent(String)}. |
| 1117 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1118 | */ |
| 1119 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1120 | |
| 1121 | /** |
| 1122 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1123 | * {@link #createAdminSupportIntent(String)}. |
| 1124 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1125 | */ |
| 1126 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1127 | |
| 1128 | /** |
| 1129 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1130 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
| 1131 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 1132 | * @see #createAdminSupportIntent(String) |
| 1133 | * @hide |
| 1134 | */ |
| 1135 | @TestApi |
| 1136 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1137 | |
| 1138 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1139 | * Activity action: have the user enter a new password. This activity should |
| 1140 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1141 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1142 | * enter a new password that meets the current requirements. You can use |
| 1143 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1144 | * have the user select a new password in order to meet the current |
| 1145 | * constraints. Upon being resumed from this activity, you can check the new |
| 1146 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1147 | * |
| 1148 | * If the intent is launched from within a managed profile with a profile |
| 1149 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1150 | * this will trigger entering a new password for the parent of the profile. |
| 1151 | * For all other cases it will trigger entering a new password for the user |
| 1152 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1153 | * |
| 1154 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1155 | */ |
| 1156 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1157 | public static final String ACTION_SET_NEW_PASSWORD |
| 1158 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1159 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1160 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1161 | * Activity action: have the user enter a new password for the parent profile. |
| 1162 | * If the intent is launched from within a managed profile, this will trigger |
| 1163 | * entering a new password for the parent of the profile. In all other cases |
| 1164 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1165 | */ |
| 1166 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1167 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1168 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1169 | |
| 1170 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1171 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1172 | * Network logging was enabled and the user tapped the notification. |
| 1173 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1174 | * @hide |
| 1175 | */ |
| 1176 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1177 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1178 | |
| 1179 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1180 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1181 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1182 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1183 | * |
| 1184 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1185 | */ |
| 1186 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1187 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1188 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1189 | |
| 1190 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1191 | * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1192 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1193 | */ |
| 1194 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1195 | |
| 1196 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1197 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1198 | * the parent profile to access intents sent from the managed profile. |
| 1199 | * That is, when an app in the managed profile calls |
| 1200 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1201 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1202 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1203 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1204 | |
| 1205 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1206 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1207 | * the managed profile to access intents sent from the parent profile. |
| 1208 | * That is, when an app in the parent profile calls |
| 1209 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1210 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1211 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1212 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1213 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1214 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1215 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1216 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1217 | */ |
| 1218 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1219 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1220 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1221 | |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1222 | /** |
| 1223 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1224 | * Already granted or denied permissions are not affected by this. |
| 1225 | */ |
| 1226 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1227 | |
| 1228 | /** |
| 1229 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1230 | * Already granted or denied permissions are not affected by this. |
| 1231 | */ |
| 1232 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1233 | |
| 1234 | /** |
| 1235 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1236 | * Already granted or denied permissions are not affected by this. |
| 1237 | */ |
| 1238 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1239 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1240 | /** |
| 1241 | * Runtime permission state: The user can manage the permission |
| 1242 | * through the UI. |
| 1243 | */ |
| 1244 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1245 | |
| 1246 | /** |
| 1247 | * Runtime permission state: The permission is granted to the app |
| 1248 | * and the user cannot manage the permission through the UI. |
| 1249 | */ |
| 1250 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1251 | |
| 1252 | /** |
| 1253 | * Runtime permission state: The permission is denied to the app |
| 1254 | * and the user cannot manage the permission through the UI. |
| 1255 | */ |
| 1256 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1257 | |
| 1258 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1259 | * Delegation of certificate installation and management. This scope grants access to the |
| 1260 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1261 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1262 | */ |
| 1263 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1264 | |
| 1265 | /** |
| 1266 | * Delegation of application restrictions management. This scope grants access to the |
| 1267 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1268 | */ |
| 1269 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1270 | |
| 1271 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1272 | * Delegation of application uninstall block. This scope grants access to the |
| 1273 | * {@link #setUninstallBlocked} API. |
| 1274 | */ |
| 1275 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1276 | |
| 1277 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1278 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1279 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1280 | * and {@link #setPermissionGrantState} APIs. |
| 1281 | */ |
| 1282 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1283 | |
| 1284 | /** |
| 1285 | * Delegation of package access state. This scope grants access to the |
| 1286 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1287 | * {@link #setPackagesSuspended} APIs. |
| 1288 | */ |
| 1289 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1290 | |
| 1291 | /** |
| 1292 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1293 | * API. |
| 1294 | */ |
| 1295 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1296 | |
| 1297 | /** |
| 1298 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1299 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1300 | * @hide |
| 1301 | */ |
| 1302 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1303 | "delegation-keep-uninstalled-packages"; |
| 1304 | |
| 1305 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1306 | * No management for current user in-effect. This is the default. |
| 1307 | * @hide |
| 1308 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1309 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1310 | public static final int STATE_USER_UNMANAGED = 0; |
| 1311 | |
| 1312 | /** |
| 1313 | * Management partially setup, user setup needs to be completed. |
| 1314 | * @hide |
| 1315 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1316 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1317 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1318 | |
| 1319 | /** |
| 1320 | * Management partially setup, user setup completed. |
| 1321 | * @hide |
| 1322 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1323 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1324 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1325 | |
| 1326 | /** |
| 1327 | * Management setup and active on current user. |
| 1328 | * @hide |
| 1329 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1330 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1331 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1332 | |
| 1333 | /** |
| 1334 | * Management partially setup on a managed profile. |
| 1335 | * @hide |
| 1336 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1337 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1338 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1339 | |
| 1340 | /** |
| 1341 | * @hide |
| 1342 | */ |
| 1343 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1344 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1345 | @Retention(RetentionPolicy.SOURCE) |
| 1346 | public @interface UserProvisioningState {} |
| 1347 | |
| 1348 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1349 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1350 | * |
| 1351 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1352 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1353 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1354 | * |
| 1355 | * @hide |
| 1356 | */ |
| 1357 | public static final int CODE_OK = 0; |
| 1358 | |
| 1359 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1360 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1361 | * |
| 1362 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1363 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1364 | * owner. |
| 1365 | * |
| 1366 | * @hide |
| 1367 | */ |
| 1368 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1369 | |
| 1370 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1371 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1372 | * |
| 1373 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1374 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1375 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1376 | * |
| 1377 | * @hide |
| 1378 | */ |
| 1379 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1380 | |
| 1381 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1382 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1383 | * |
| 1384 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1385 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1386 | * |
| 1387 | * @hide |
| 1388 | */ |
| 1389 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1390 | |
| 1391 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1392 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1393 | * |
| 1394 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1395 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1396 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1397 | * |
| 1398 | * @hide |
| 1399 | */ |
| 1400 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1401 | |
| 1402 | /** |
| 1403 | * Code used to indicate that the device also has a user other than the system user. |
| 1404 | * |
| 1405 | * @hide |
| 1406 | */ |
| 1407 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1408 | |
| 1409 | /** |
| 1410 | * Code used to indicate that device has an account that prevents provisioning. |
| 1411 | * |
| 1412 | * @hide |
| 1413 | */ |
| 1414 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1415 | |
| 1416 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1417 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1418 | * |
| 1419 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1420 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1421 | * |
| 1422 | * @hide |
| 1423 | */ |
| 1424 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1425 | |
| 1426 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1427 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1428 | * |
| 1429 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1430 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1431 | * when the device is a watch and is already paired. |
| 1432 | * |
| 1433 | * @hide |
| 1434 | */ |
| 1435 | public static final int CODE_HAS_PAIRED = 8; |
| 1436 | |
| 1437 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1438 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1439 | * |
| 1440 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1441 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1442 | * |
| 1443 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1444 | * @hide |
| 1445 | */ |
| 1446 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1447 | |
| 1448 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1449 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1450 | * |
| 1451 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1452 | * |
| 1453 | * @hide |
| 1454 | */ |
| 1455 | public static final int CODE_SYSTEM_USER = 10; |
| 1456 | |
| 1457 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1458 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1459 | * |
| 1460 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1461 | * managed profiles. |
| 1462 | * |
| 1463 | * @hide |
| 1464 | */ |
| 1465 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1466 | |
| 1467 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1468 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1469 | * |
| 1470 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1471 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1472 | * user. |
| 1473 | * |
| 1474 | * @hide |
| 1475 | */ |
| 1476 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1477 | |
| 1478 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1479 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1480 | * |
| 1481 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1482 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1483 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1484 | * admins. |
| 1485 | * |
| 1486 | * @hide |
| 1487 | */ |
| 1488 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1489 | |
| 1490 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1491 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1492 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1493 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1494 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1495 | * |
| 1496 | * @hide |
| 1497 | */ |
| 1498 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1499 | |
| 1500 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1501 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1502 | * |
| 1503 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1504 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1505 | * |
| 1506 | * @hide |
| 1507 | */ |
| 1508 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1509 | |
| 1510 | /** |
| 1511 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1512 | * conditions. |
| 1513 | * |
| 1514 | * @hide |
| 1515 | */ |
| 1516 | @Retention(RetentionPolicy.SOURCE) |
| 1517 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1518 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1519 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1520 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1521 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1522 | public @interface ProvisioningPreCondition {} |
| 1523 | |
| 1524 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1525 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1526 | * |
| 1527 | * @param admin The administrator component to check for. |
| 1528 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1529 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1530 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1531 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1532 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1533 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * @see #isAdminActive(ComponentName) |
| 1538 | * @hide |
| 1539 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1540 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1541 | if (mService != null) { |
| 1542 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1543 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1544 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1545 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1546 | } |
| 1547 | } |
| 1548 | return false; |
| 1549 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1550 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1551 | /** |
| 1552 | * Return true if the given administrator component is currently being removed |
| 1553 | * for the user. |
| 1554 | * @hide |
| 1555 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1556 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1557 | if (mService != null) { |
| 1558 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1559 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1560 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1561 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | return false; |
| 1565 | } |
| 1566 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1567 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1568 | * Return a list of all currently active device administrators' component |
| 1569 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1570 | * returned. |
| 1571 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1572 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1573 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1574 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | /** |
| 1578 | * @see #getActiveAdmins() |
| 1579 | * @hide |
| 1580 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1581 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1582 | if (mService != null) { |
| 1583 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1584 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1585 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1586 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | return null; |
| 1590 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1591 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1592 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1593 | * Used by package administration code to determine if a package can be stopped |
| 1594 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1595 | * @hide |
| 1596 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1597 | @SystemApi |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1598 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1599 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1600 | } |
| 1601 | |
| 1602 | /** |
| 1603 | * Used by package administration code to determine if a package can be stopped |
| 1604 | * or uninstalled. |
| 1605 | * @hide |
| 1606 | */ |
| 1607 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1608 | if (mService != null) { |
| 1609 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1610 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1611 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1612 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | return false; |
| 1616 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1617 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1618 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1619 | * Remove a current administration component. This can only be called |
| 1620 | * by the application that owns the administration component; if you |
| 1621 | * try to remove someone else's component, a security exception will be |
| 1622 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1623 | * |
| 1624 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1625 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1626 | * |
| 1627 | * @param admin The administration compononent to remove. |
| 1628 | * @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] | 1629 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1630 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1631 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1632 | if (mService != null) { |
| 1633 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1634 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1635 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1636 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1640 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1641 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1642 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1643 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1644 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1645 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1646 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1647 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1648 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1649 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1650 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1651 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1652 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1653 | if (mService != null) { |
| 1654 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1655 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1656 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1657 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | return false; |
| 1661 | } |
| 1662 | |
| 1663 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1664 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1665 | * |
| 1666 | * @hide |
| 1667 | */ |
| 1668 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1669 | if (mService != null) { |
| 1670 | try { |
| 1671 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1672 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1673 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1674 | } |
| 1675 | } |
| 1676 | return false; |
| 1677 | } |
| 1678 | |
| 1679 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1680 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1681 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1682 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1683 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1684 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1685 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1686 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1687 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1688 | * recognition technology. This implies technologies that can recognize the identity of |
| 1689 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1690 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1691 | */ |
| 1692 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1693 | |
| 1694 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1695 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1696 | * 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] | 1697 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1698 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1699 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1700 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1701 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1702 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1703 | * password containing at least numeric characters. Note that quality |
| 1704 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1705 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1706 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1707 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1708 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1709 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1710 | * password containing at least numeric characters with no repeating (4444) |
| 1711 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1712 | * constants are ordered so that higher values are more restrictive. |
| 1713 | */ |
| 1714 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1715 | |
| 1716 | /** |
| 1717 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1718 | * password containing at least alphabetic (or other symbol) characters. |
| 1719 | * Note that quality constants are ordered so that higher values are more |
| 1720 | * restrictive. |
| 1721 | */ |
| 1722 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1723 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1724 | /** |
| 1725 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1726 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1727 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1728 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1729 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1730 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1731 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1732 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1733 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1734 | * password containing at least a letter, a numerical digit and a special |
| 1735 | * symbol, by default. With this password quality, passwords can be |
| 1736 | * restricted to contain various sets of characters, like at least an |
| 1737 | * uppercase letter, etc. These are specified using various methods, |
| 1738 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1739 | * that quality constants are ordered so that higher values are more |
| 1740 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1741 | */ |
| 1742 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1743 | |
| 1744 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1745 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1746 | * modify password. In case this password quality is set, the password is |
| 1747 | * managed by a profile owner. The profile owner can set any password, |
| 1748 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1749 | * that quality constants are ordered so that higher values are more |
| 1750 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1751 | * the highest. |
| 1752 | * @hide |
| 1753 | */ |
| 1754 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1755 | |
| 1756 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1757 | * @hide |
| 1758 | * |
| 1759 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1760 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1761 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1762 | * used by authenticator to exempt their accounts from this: |
| 1763 | * |
| 1764 | * <ul> |
| 1765 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1766 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1767 | * <application> tag in the manifest. |
| 1768 | * |
| 1769 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1770 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1771 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1772 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1773 | * if any of the accounts have it. |
| 1774 | * </ul> |
| 1775 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame^] | 1776 | @SystemApi |
| 1777 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1778 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1779 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1780 | |
| 1781 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame^] | 1782 | @SystemApi |
| 1783 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1784 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1785 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1786 | |
| 1787 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1788 | * Called by an application that is administering the device to set the password restrictions it |
| 1789 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1790 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1791 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1792 | * 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] | 1793 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1794 | * <p> |
| 1795 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1796 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1797 | * considerations) is the one that is in effect. |
| 1798 | * <p> |
| 1799 | * The calling device admin must have requested |
| 1800 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1801 | * not, a security exception will be thrown. |
| 1802 | * <p> |
| 1803 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1804 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1805 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1806 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1807 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1808 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1809 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1810 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1811 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1812 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1813 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1814 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1815 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1816 | if (mService != null) { |
| 1817 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1818 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1819 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1820 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1821 | } |
| 1822 | } |
| 1823 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1824 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1825 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1826 | * 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] | 1827 | * 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] | 1828 | * a separate challenge are not taken into account. |
| 1829 | * |
| 1830 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1831 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1832 | * restrictions on the parent profile. |
| 1833 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1834 | * @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] | 1835 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1836 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1837 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1838 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1842 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1843 | if (mService != null) { |
| 1844 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1845 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1846 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1847 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1848 | } |
| 1849 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1850 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1851 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1852 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1853 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1854 | * Called by an application that is administering the device to set the minimum allowed password |
| 1855 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1856 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1857 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1858 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1859 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1860 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1861 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1862 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1863 | * {@link #setPasswordQuality}. |
| 1864 | * <p> |
| 1865 | * The calling device admin must have requested |
| 1866 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1867 | * not, a security exception will be thrown. |
| 1868 | * <p> |
| 1869 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1870 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1871 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1872 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1873 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1874 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1875 | * restriction. |
| 1876 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1877 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1878 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1879 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1880 | if (mService != null) { |
| 1881 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1882 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1883 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1884 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1888 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1889 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1890 | * 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] | 1891 | * 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] | 1892 | * a separate challenge are not taken into account. |
| 1893 | * |
| 1894 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1895 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1896 | * restrictions on the parent profile. |
| 1897 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1898 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1899 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1900 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1901 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1902 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1903 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1907 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1908 | if (mService != null) { |
| 1909 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1910 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1911 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1912 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1913 | } |
| 1914 | } |
| 1915 | return 0; |
| 1916 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1917 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1918 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1919 | * Called by an application that is administering the device to set the minimum number of upper |
| 1920 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1921 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1922 | * current password will remain until the user has set a new one, so the change does not take |
| 1923 | * place immediately. To prompt the user for a new password, use |
| 1924 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1925 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1926 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1927 | * <p> |
| 1928 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1929 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1930 | * not, a security exception will be thrown. |
| 1931 | * <p> |
| 1932 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1933 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1934 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1935 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1936 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1937 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1938 | * A value of 0 means there is no restriction. |
| 1939 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1940 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1941 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1942 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1943 | if (mService != null) { |
| 1944 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1945 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1946 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1947 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1953 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1954 | * 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] | 1955 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1956 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1957 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1958 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1959 | * and only applies when the password quality is |
| 1960 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1961 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1962 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1963 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1964 | * restrictions on the parent profile. |
| 1965 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1966 | * @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] | 1967 | * aggregate all admins. |
| 1968 | * @return The minimum number of upper case letters required in the |
| 1969 | * password. |
| 1970 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1971 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1972 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1976 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1977 | if (mService != null) { |
| 1978 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1979 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1980 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1981 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1982 | } |
| 1983 | } |
| 1984 | return 0; |
| 1985 | } |
| 1986 | |
| 1987 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1988 | * Called by an application that is administering the device to set the minimum number of lower |
| 1989 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1990 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1991 | * current password will remain until the user has set a new one, so the change does not take |
| 1992 | * place immediately. To prompt the user for a new password, use |
| 1993 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1994 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1995 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1996 | * <p> |
| 1997 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1998 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1999 | * not, a security exception will be thrown. |
| 2000 | * <p> |
| 2001 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2002 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2003 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2004 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2005 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2006 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2007 | * A value of 0 means there is no restriction. |
| 2008 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2009 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2010 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2011 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2012 | if (mService != null) { |
| 2013 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2014 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2015 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2016 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2017 | } |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2022 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2023 | * 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] | 2024 | * and its participating profiles. Restrictions on profiles that have |
| 2025 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2026 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2027 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2028 | * and only applies when the password quality is |
| 2029 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2030 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2031 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2032 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2033 | * restrictions on the parent profile. |
| 2034 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2035 | * @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] | 2036 | * aggregate all admins. |
| 2037 | * @return The minimum number of lower case letters required in the |
| 2038 | * password. |
| 2039 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2040 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2041 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2045 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2046 | if (mService != null) { |
| 2047 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2048 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2049 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2050 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
| 2056 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2057 | * Called by an application that is administering the device to set the minimum number of |
| 2058 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2059 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2060 | * password will remain until the user has set a new one, so the change does not take place |
| 2061 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2062 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2063 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2064 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2065 | * <p> |
| 2066 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2067 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2068 | * not, a security exception will be thrown. |
| 2069 | * <p> |
| 2070 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2071 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2072 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2073 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2074 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2075 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2076 | * 0 means there is no restriction. |
| 2077 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2078 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2079 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2080 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2081 | if (mService != null) { |
| 2082 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2083 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2084 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2085 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | } |
| 2089 | |
| 2090 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2091 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2092 | * 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] | 2093 | * and its participating profiles. Restrictions on profiles that have |
| 2094 | * a separate challenge are not taken into account. |
| 2095 | * This is the same value as set by |
| 2096 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2097 | * and only applies when the password quality is |
| 2098 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2099 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2100 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2101 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2102 | * restrictions on the parent profile. |
| 2103 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2104 | * @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] | 2105 | * aggregate all admins. |
| 2106 | * @return The minimum number of letters required in the password. |
| 2107 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2108 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2109 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2113 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2114 | if (mService != null) { |
| 2115 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2116 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2117 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2118 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
| 2124 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2125 | * Called by an application that is administering the device to set the minimum number of |
| 2126 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2127 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2128 | * current password will remain until the user has set a new one, so the change does not take |
| 2129 | * place immediately. To prompt the user for a new password, use |
| 2130 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2131 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2132 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2133 | * <p> |
| 2134 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2135 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2136 | * not, a security exception will be thrown. |
| 2137 | * <p> |
| 2138 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2139 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2140 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2141 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2142 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2143 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2144 | * value of 0 means there is no restriction. |
| 2145 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2146 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2147 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2148 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2149 | if (mService != null) { |
| 2150 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2151 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2152 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2153 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | /** |
| 2159 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2160 | * 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] | 2161 | * and its participating profiles. Restrictions on profiles that have |
| 2162 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2163 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2164 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2165 | * and only applies when the password quality is |
| 2166 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2167 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2168 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2169 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2170 | * restrictions on the parent profile. |
| 2171 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2172 | * @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] | 2173 | * aggregate all admins. |
| 2174 | * @return The minimum number of numerical digits required in the password. |
| 2175 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2176 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2177 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2181 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2182 | if (mService != null) { |
| 2183 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2184 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2185 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2186 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2187 | } |
| 2188 | } |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2193 | * Called by an application that is administering the device to set the minimum number of |
| 2194 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2195 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2196 | * password will remain until the user has set a new one, so the change does not take place |
| 2197 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2198 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2199 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2200 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2201 | * <p> |
| 2202 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2203 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2204 | * not, a security exception will be thrown. |
| 2205 | * <p> |
| 2206 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2207 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2208 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2209 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2211 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2212 | * 0 means there is no restriction. |
| 2213 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2214 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2215 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2216 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2217 | if (mService != null) { |
| 2218 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2219 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -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 | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2227 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2228 | * 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] | 2229 | * and its participating profiles. Restrictions on profiles that have |
| 2230 | * a separate challenge are not taken into account. This is the same value as |
| 2231 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2232 | * and only applies when the password quality is |
| 2233 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2234 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2235 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2236 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2237 | * restrictions on the parent profile. |
| 2238 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2239 | * @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] | 2240 | * aggregate all admins. |
| 2241 | * @return The minimum number of symbols required in the password. |
| 2242 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2243 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2244 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2248 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2249 | if (mService != null) { |
| 2250 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2251 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2252 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2253 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | return 0; |
| 2257 | } |
| 2258 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2259 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2260 | * Called by an application that is administering the device to set the minimum number of |
| 2261 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2262 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2263 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2264 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2265 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2266 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2267 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2268 | * <p> |
| 2269 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2270 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2271 | * not, a security exception will be thrown. |
| 2272 | * <p> |
| 2273 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2274 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2275 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2276 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2277 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2278 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2279 | * 0 means there is no restriction. |
| 2280 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2281 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2282 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2283 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2284 | if (mService != null) { |
| 2285 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2286 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2287 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2288 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2294 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2295 | * 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] | 2296 | * and its participating profiles. Restrictions on profiles that have |
| 2297 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2298 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2299 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2300 | * and only applies when the password quality is |
| 2301 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2302 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2303 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2304 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2305 | * restrictions on the parent profile. |
| 2306 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2307 | * @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] | 2308 | * aggregate all admins. |
| 2309 | * @return The minimum number of letters required in the password. |
| 2310 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2311 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2312 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2316 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2317 | if (mService != null) { |
| 2318 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2319 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2320 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2321 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2322 | } |
| 2323 | } |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2327 | /** |
| 2328 | * Called by an application that is administering the device to set the length of the password |
| 2329 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2330 | * same as any password in the history. Note that the current password will remain until the |
| 2331 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2332 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2333 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2334 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2335 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2336 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2337 | * <p> |
| 2338 | * The calling device admin must have requested |
| 2339 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2340 | * not, a security exception will be thrown. |
| 2341 | * <p> |
| 2342 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2343 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2344 | * profile. |
| 2345 | * |
| 2346 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2347 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2348 | * restriction. |
| 2349 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2350 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2351 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2352 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2353 | if (mService != null) { |
| 2354 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2355 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2356 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2357 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2358 | } |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2363 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2364 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2365 | * device password (for all admins). |
| 2366 | * <p> |
| 2367 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2368 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2369 | * 432000000 ms for timeout. |
| 2370 | * <p> |
| 2371 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2372 | * <p> |
| 2373 | * The calling device admin must have requested |
| 2374 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2375 | * not, a security exception will be thrown. |
| 2376 | * <p> |
| 2377 | * Note that setting the password will automatically reset the expiration time for all active |
| 2378 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2379 | * <p> |
| 2380 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2381 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2382 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2383 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2384 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2385 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2386 | * there is no restriction (unlimited). |
| 2387 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2388 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2389 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2390 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2391 | if (mService != null) { |
| 2392 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2393 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2394 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2395 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2396 | } |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2401 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2402 | * recurring expiration timeout provided in the call to |
| 2403 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2404 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2405 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2406 | * |
| 2407 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2408 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2409 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2410 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2411 | * @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] | 2412 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2413 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2414 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2415 | if (mService != null) { |
| 2416 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2417 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2418 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2419 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | return 0; |
| 2423 | } |
| 2424 | |
| 2425 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2426 | * 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] | 2427 | * 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] | 2428 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2429 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2430 | * |
| 2431 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2432 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2433 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2434 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2435 | * @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] | 2436 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2437 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2438 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2439 | if (mService != null) { |
| 2440 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2441 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2442 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2443 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2444 | } |
| 2445 | } |
| 2446 | return 0; |
| 2447 | } |
| 2448 | |
| 2449 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2450 | * 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] | 2451 | * 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] | 2452 | * have a separate challenge are not taken into account. |
| 2453 | * |
| 2454 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2455 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2456 | * restrictions on the parent profile. |
| 2457 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2458 | * @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] | 2459 | * all admins. |
| 2460 | * @return The length of the password history |
| 2461 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2462 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2463 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2467 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2468 | if (mService != null) { |
| 2469 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2470 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2471 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2472 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2478 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2479 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2480 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2481 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2482 | * @return Returns the maximum length that the user can enter. |
| 2483 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2484 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2485 | // Kind-of arbitrary. |
| 2486 | return 16; |
| 2487 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2488 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2489 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2490 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2491 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2492 | * 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] | 2493 | * 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] | 2494 | * <p> |
| 2495 | * The calling device admin must have requested |
| 2496 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2497 | * not, a security exception will be thrown. |
| 2498 | * <p> |
| 2499 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2500 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2501 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2502 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2503 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2504 | * @throws SecurityException if the calling application does not own an active administrator |
| 2505 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2506 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2507 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2508 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2509 | if (mService != null) { |
| 2510 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2511 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2512 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2513 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2514 | } |
| 2515 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2516 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2517 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2518 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2519 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2520 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2521 | * 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] | 2522 | * requested by the admins of the parent user and its profiles. |
| 2523 | * |
| 2524 | * @param userHandle the userId of the profile to check the password for. |
| 2525 | * @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] | 2526 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2527 | * @hide |
| 2528 | */ |
| 2529 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2530 | if (mService != null) { |
| 2531 | try { |
| 2532 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2533 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2534 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | return false; |
| 2538 | } |
| 2539 | |
| 2540 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2541 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2542 | * successful password entry. |
| 2543 | * <p> |
| 2544 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2545 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2546 | * password attemts for the parent user. |
| 2547 | * <p> |
| 2548 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2549 | * 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] | 2550 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2551 | * @return The number of times user has entered an incorrect password since the last correct |
| 2552 | * password entry. |
| 2553 | * @throws SecurityException if the calling application does not own an active administrator |
| 2554 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2555 | */ |
| 2556 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2557 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2558 | } |
| 2559 | |
| 2560 | /** |
| 2561 | * Retrieve the number of times the given user has failed at entering a |
| 2562 | * password since that last successful password entry. |
| 2563 | * |
| 2564 | * <p>The calling device admin must have requested |
| 2565 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2566 | * not and it is not the system uid, a security exception will be thrown. |
| 2567 | * |
| 2568 | * @hide |
| 2569 | */ |
| 2570 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2571 | if (mService != null) { |
| 2572 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2573 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2574 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2575 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | return -1; |
| 2579 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2580 | |
| 2581 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2582 | * 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] | 2583 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2584 | * @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] | 2585 | * @hide |
| 2586 | */ |
| 2587 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2588 | if (mService != null) { |
| 2589 | try { |
| 2590 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2591 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2592 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | return false; |
| 2596 | } |
| 2597 | |
| 2598 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2599 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2600 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2601 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2602 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2603 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2604 | * <p> |
| 2605 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2606 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2607 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2608 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2609 | * immediately, and your callback will not be invoked. |
| 2610 | * <p> |
| 2611 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2612 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2613 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2614 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2615 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2616 | * @param num The number of failed password attempts at which point the device or profile will |
| 2617 | * be wiped. |
| 2618 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2619 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2620 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2621 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2622 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2623 | if (mService != null) { |
| 2624 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2625 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2626 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2627 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2631 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2632 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2633 | * 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] | 2634 | * 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] | 2635 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2636 | * not taken into account. |
| 2637 | * |
| 2638 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2639 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2640 | * the value for the parent profile. |
| 2641 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2642 | * @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] | 2643 | * all admins. |
| 2644 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2645 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2646 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2650 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2651 | if (mService != null) { |
| 2652 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2653 | return mService.getMaximumFailedPasswordsForWipe( |
| 2654 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2655 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2656 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | return 0; |
| 2660 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2661 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2662 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2663 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2664 | * for the given user. So for primary user, it might return the primary or |
| 2665 | * a managed profile. For a secondary user, it would be the same as the |
| 2666 | * user passed in. |
| 2667 | * @hide Used only by Keyguard |
| 2668 | */ |
| 2669 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2670 | if (mService != null) { |
| 2671 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2672 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2673 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2674 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2675 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2676 | } |
| 2677 | } |
| 2678 | return UserHandle.USER_NULL; |
| 2679 | } |
| 2680 | |
| 2681 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2682 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2683 | * the password again until the user has entered it. |
| 2684 | */ |
| 2685 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2686 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2687 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2688 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2689 | * If the flag is set, the device can be booted without asking for user password. |
| 2690 | * The absence of this flag does not change the current boot requirements. This flag |
| 2691 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2692 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2693 | * device to factory defaults. |
| 2694 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2695 | 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] | 2696 | |
| 2697 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2698 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2699 | * individual accounts) on the user. This takes effect immediately. |
| 2700 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2701 | * <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] | 2702 | * device admins that are not device owner and not profile owner. |
| 2703 | * 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] | 2704 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2705 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2706 | * <p> |
| 2707 | * The given password must be sufficient for the current password quality and length constraints |
| 2708 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2709 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2710 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2711 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2712 | * case the currently active quality will be increased to match. |
| 2713 | * <p> |
| 2714 | * 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] | 2715 | * current password constraints allow it. <em>Note: This will not work in |
| 2716 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2717 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2718 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2719 | * <p> |
| 2720 | * The calling device admin must have requested |
| 2721 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2722 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2723 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2724 | * @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] | 2725 | * @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] | 2726 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2727 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2728 | * current constraints or if the user has not been decrypted yet. |
| 2729 | * @throws SecurityException if the calling application does not own an active administrator |
| 2730 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2731 | * @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] | 2732 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2733 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2734 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2735 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2736 | if (mService != null) { |
| 2737 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2738 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2739 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2740 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2741 | } |
| 2742 | } |
| 2743 | return false; |
| 2744 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2745 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2746 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2747 | * Called by an application that is administering the device to set the maximum time for user |
| 2748 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2749 | * effect immediately. |
| 2750 | * <p> |
| 2751 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2752 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2753 | * <p> |
| 2754 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2755 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2756 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2757 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2758 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2759 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2760 | * is no restriction. |
| 2761 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2762 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2763 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2764 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2765 | if (mService != null) { |
| 2766 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2767 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2768 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2769 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2770 | } |
| 2771 | } |
| 2772 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2773 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2774 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2775 | * 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] | 2776 | * 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] | 2777 | * a separate challenge are not taken into account. |
| 2778 | * |
| 2779 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2780 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2781 | * restrictions on the parent profile. |
| 2782 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2783 | * @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] | 2784 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2785 | * @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] | 2786 | * 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] | 2787 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2788 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2789 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2793 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2794 | if (mService != null) { |
| 2795 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2796 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2797 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2798 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | return 0; |
| 2802 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2803 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2804 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2805 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2806 | * do not have a separate timeout to lock for work challenge only. |
| 2807 | * |
| 2808 | * @hide |
| 2809 | */ |
| 2810 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2811 | if (mService != null) { |
| 2812 | try { |
| 2813 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2814 | } catch (RemoteException e) { |
| 2815 | throw e.rethrowFromSystemServer(); |
| 2816 | } |
| 2817 | } |
| 2818 | return 0; |
| 2819 | } |
| 2820 | |
| 2821 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2822 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2823 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2824 | * authentication method like password, pin or pattern. |
| 2825 | * |
| 2826 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2827 | * specified timeout each time it has been successfully used. |
| 2828 | * |
| 2829 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2830 | * |
| 2831 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2832 | * |
| 2833 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2834 | * a {@link SecurityException} will be thrown. |
| 2835 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2836 | * <p>The calling device admin can verify the value it has set by calling |
| 2837 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2838 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2839 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2840 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2841 | * profile. |
| 2842 | * |
| 2843 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2844 | * @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] | 2845 | * authentication method. A value of 0 means the admin is not participating in |
| 2846 | * controlling the timeout. |
| 2847 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2848 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2849 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2850 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2851 | * |
| 2852 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2853 | */ |
| 2854 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2855 | long timeoutMs) { |
| 2856 | if (mService != null) { |
| 2857 | try { |
| 2858 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2859 | } catch (RemoteException e) { |
| 2860 | throw e.rethrowFromSystemServer(); |
| 2861 | } |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 2867 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 2868 | * After the returned timeout the user is required to use strong authentication method. |
| 2869 | * |
| 2870 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2871 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2872 | * restrictions on the parent profile. |
| 2873 | * |
| 2874 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 2875 | * accross all participating admins. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2876 | * @return The timeout or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2877 | */ |
| 2878 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 2879 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 2880 | } |
| 2881 | |
| 2882 | /** @hide per-user version */ |
| 2883 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 2884 | if (mService != null) { |
| 2885 | try { |
| 2886 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 2887 | } catch (RemoteException e) { |
| 2888 | throw e.rethrowFromSystemServer(); |
| 2889 | } |
| 2890 | } |
| 2891 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 2892 | } |
| 2893 | |
| 2894 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2895 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 2896 | * keyring. The user's credential will need to be entered again in order to derive the |
| 2897 | * credential encryption key that will be stored back in the keyring for future use. |
| 2898 | * <p> |
| 2899 | * This flag can only be used by a profile owner when locking a managed profile on an FBE |
| 2900 | * device. |
| 2901 | * <p> |
| 2902 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 2903 | * until they are next run to perform further actions. |
| 2904 | */ |
| 2905 | public static final int FLAG_EVICT_CE_KEY = 1; |
| 2906 | |
| 2907 | /** @hide */ |
| 2908 | @Retention(RetentionPolicy.SOURCE) |
| 2909 | @IntDef(flag=true, value={FLAG_EVICT_CE_KEY}) |
| 2910 | public @interface LockNowFlag {} |
| 2911 | |
| 2912 | /** |
| 2913 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2914 | * this call. |
| 2915 | * <p> |
| 2916 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2917 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2918 | * <p> |
| 2919 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2920 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 2921 | * <p> |
| 2922 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 2923 | * |
| 2924 | * @throws SecurityException if the calling application does not own an active administrator |
| 2925 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2926 | */ |
| 2927 | public void lockNow() { |
| 2928 | lockNow(0); |
| 2929 | } |
| 2930 | |
| 2931 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2932 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2933 | * this call. |
| 2934 | * <p> |
| 2935 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2936 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2937 | * <p> |
| 2938 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2939 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2940 | * |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2941 | * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2942 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2943 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
| 2944 | * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile |
| 2945 | * owner of a managed profile. |
| 2946 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when |
| 2947 | * locking the parent profile. |
| 2948 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a |
| 2949 | * non-FBE device. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2950 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2951 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2952 | if (mService != null) { |
| 2953 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2954 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2955 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2956 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2960 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2961 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2962 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2963 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2964 | */ |
| 2965 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2966 | |
| 2967 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2968 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2969 | * data. |
| 2970 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2971 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2972 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2973 | */ |
| 2974 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2975 | |
| 2976 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 2977 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 2978 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 2979 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 2980 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2981 | * <p> |
| 2982 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2983 | * 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] | 2984 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2985 | * @param flags Bit mask of additional options: currently supported flags are |
| 2986 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2987 | * @throws SecurityException if the calling application does not own an active administrator |
| 2988 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2989 | */ |
| 2990 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2991 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2992 | if (mService != null) { |
| 2993 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2994 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2995 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2996 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3000 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3001 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3002 | * Called by an application that is administering the device to set the |
| 3003 | * global proxy and exclusion list. |
| 3004 | * <p> |
| 3005 | * The calling device admin must have requested |
| 3006 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3007 | * this method; if it has not, a security exception will be thrown. |
| 3008 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3009 | * 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] | 3010 | * 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] | 3011 | * be returned. |
| 3012 | * The method can be called repeatedly by the device admin alrady setting the |
| 3013 | * proxy to update the proxy and exclusion list. |
| 3014 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3015 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3016 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3017 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3018 | * @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] | 3019 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3020 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3021 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3022 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3023 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3024 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3025 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3026 | if (proxySpec == null) { |
| 3027 | throw new NullPointerException(); |
| 3028 | } |
| 3029 | if (mService != null) { |
| 3030 | try { |
| 3031 | String hostSpec; |
| 3032 | String exclSpec; |
| 3033 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3034 | hostSpec = null; |
| 3035 | exclSpec = null; |
| 3036 | } else { |
| 3037 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3038 | throw new IllegalArgumentException(); |
| 3039 | } |
| 3040 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3041 | String hostName = sa.getHostName(); |
| 3042 | int port = sa.getPort(); |
| 3043 | StringBuilder hostBuilder = new StringBuilder(); |
| 3044 | hostSpec = hostBuilder.append(hostName) |
| 3045 | .append(":").append(Integer.toString(port)).toString(); |
| 3046 | if (exclusionList == null) { |
| 3047 | exclSpec = ""; |
| 3048 | } else { |
| 3049 | StringBuilder listBuilder = new StringBuilder(); |
| 3050 | boolean firstDomain = true; |
| 3051 | for (String exclDomain : exclusionList) { |
| 3052 | if (!firstDomain) { |
| 3053 | listBuilder = listBuilder.append(","); |
| 3054 | } else { |
| 3055 | firstDomain = false; |
| 3056 | } |
| 3057 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3058 | } |
| 3059 | exclSpec = listBuilder.toString(); |
| 3060 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3061 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3062 | != android.net.Proxy.PROXY_VALID) |
| 3063 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3064 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3065 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3066 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3067 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3068 | } |
| 3069 | } |
| 3070 | return null; |
| 3071 | } |
| 3072 | |
| 3073 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3074 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3075 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3076 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3077 | * proxy is not accessible, you may break HTTP using this. |
| 3078 | * <p> |
| 3079 | * This method requires the caller to be the device owner. |
| 3080 | * <p> |
| 3081 | * 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] | 3082 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3083 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3084 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3085 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3086 | * {@code null} value will clear the global HTTP proxy. |
| 3087 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3088 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3089 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3090 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3091 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3092 | if (mService != null) { |
| 3093 | try { |
| 3094 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3095 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3096 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3102 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3103 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3104 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3105 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3106 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3107 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3108 | if (mService != null) { |
| 3109 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3110 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3111 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3112 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3113 | } |
| 3114 | } |
| 3115 | return null; |
| 3116 | } |
| 3117 | |
| 3118 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3119 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3120 | * indicating that encryption is not supported. |
| 3121 | */ |
| 3122 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3123 | |
| 3124 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3125 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3126 | * indicating that encryption is supported, but is not currently active. |
| 3127 | */ |
| 3128 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3129 | |
| 3130 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3131 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3132 | * indicating that encryption is not currently active, but is currently |
| 3133 | * being activated. This is only reported by devices that support |
| 3134 | * encryption of data and only when the storage is currently |
| 3135 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3136 | * to become encrypted will never return this value. |
| 3137 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3138 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3139 | |
| 3140 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3141 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3142 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3143 | * <p> |
| 3144 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3145 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3146 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3147 | |
| 3148 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3149 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3150 | * indicating that encryption is active, but an encryption key has not |
| 3151 | * been set by the user. |
| 3152 | */ |
| 3153 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3154 | |
| 3155 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3156 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3157 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3158 | * <p> |
| 3159 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3160 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3161 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3162 | */ |
| 3163 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3164 | |
| 3165 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3166 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3167 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3168 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3169 | * to check encryption status. However, on some devices this activity may never return, as |
| 3170 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3171 | */ |
| 3172 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3173 | public static final String ACTION_START_ENCRYPTION |
| 3174 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3175 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3176 | * Widgets are enabled in keyguard |
| 3177 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3178 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3179 | |
| 3180 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3181 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3182 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3183 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3184 | |
| 3185 | /** |
| 3186 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3187 | */ |
| 3188 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3189 | |
| 3190 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3191 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3192 | */ |
| 3193 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3194 | |
| 3195 | /** |
| 3196 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3197 | */ |
| 3198 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3199 | |
| 3200 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3201 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3202 | * (e.g. PIN/Pattern/Password). |
| 3203 | */ |
| 3204 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3205 | |
| 3206 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3207 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3208 | */ |
| 3209 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3210 | |
| 3211 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3212 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3213 | */ |
| 3214 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3215 | |
| 3216 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3217 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3218 | */ |
| 3219 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3220 | |
| 3221 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3222 | * Called by an application that is administering the device to request that the storage system |
| 3223 | * be encrypted. |
| 3224 | * <p> |
| 3225 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3226 | * supported setting will always be used. If any device administrator requests device |
| 3227 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3228 | * 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] | 3229 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3230 | * <p> |
| 3231 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3232 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3233 | * control the encryption of any other storage areas. There is one exception: If |
| 3234 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3235 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3236 | * written to disk within the encrypted storage area. |
| 3237 | * <p> |
| 3238 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3239 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3240 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3241 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3242 | * |
| 3243 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3244 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3245 | * @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] | 3246 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3247 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3248 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3249 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3250 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3251 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3252 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3253 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3254 | if (mService != null) { |
| 3255 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3256 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3257 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3258 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3259 | } |
| 3260 | } |
| 3261 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3262 | } |
| 3263 | |
| 3264 | /** |
| 3265 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3266 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3267 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3268 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3269 | * this will return the requested encryption setting as an aggregate of all active |
| 3270 | * administrators. |
| 3271 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3272 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3273 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3274 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3275 | if (mService != null) { |
| 3276 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3277 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3278 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3279 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3280 | } |
| 3281 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3282 | return false; |
| 3283 | } |
| 3284 | |
| 3285 | /** |
| 3286 | * Called by an application that is administering the device to |
| 3287 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3288 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3289 | * Depending on the returned status code, the caller may proceed in different |
| 3290 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3291 | * storage system does not support encryption. If the |
| 3292 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3293 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3294 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3295 | * 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] | 3296 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3297 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3298 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3299 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3300 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3301 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3302 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3303 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3304 | */ |
| 3305 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3306 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3307 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | /** @hide per-user version */ |
| 3311 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3312 | if (mService != null) { |
| 3313 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3314 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3315 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3316 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3317 | } |
| 3318 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3319 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3320 | } |
| 3321 | |
| 3322 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3323 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3324 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3325 | * keep the certificate on the device. |
| 3326 | * |
| 3327 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3328 | * this certificate. |
| 3329 | * |
| 3330 | * @hide |
| 3331 | */ |
| 3332 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3333 | if (mService != null) { |
| 3334 | try { |
| 3335 | return mService.approveCaCert(alias, userHandle, approval); |
| 3336 | } catch (RemoteException e) { |
| 3337 | throw e.rethrowFromSystemServer(); |
| 3338 | } |
| 3339 | } |
| 3340 | return false; |
| 3341 | } |
| 3342 | |
| 3343 | /** |
| 3344 | * Check whether a CA certificate has been approved by the device user. |
| 3345 | * |
| 3346 | * @hide |
| 3347 | */ |
| 3348 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3349 | if (mService != null) { |
| 3350 | try { |
| 3351 | return mService.isCaCertApproved(alias, userHandle); |
| 3352 | } catch (RemoteException e) { |
| 3353 | throw e.rethrowFromSystemServer(); |
| 3354 | } |
| 3355 | } |
| 3356 | return false; |
| 3357 | } |
| 3358 | |
| 3359 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3360 | * Installs the given certificate as a user CA. |
| 3361 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3362 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3363 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3364 | * security exception will be thrown. |
| 3365 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3366 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3367 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3368 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3369 | * |
| 3370 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3371 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3372 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3373 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3374 | * @see #setDelegatedScopes |
| 3375 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3376 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3377 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3378 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3379 | if (mService != null) { |
| 3380 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3381 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3382 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3383 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3384 | } |
| 3385 | } |
| 3386 | return false; |
| 3387 | } |
| 3388 | |
| 3389 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3390 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3391 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3392 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3393 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3394 | * security exception will be thrown. |
| 3395 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3396 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3397 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3398 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3399 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3400 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3401 | * @see #setDelegatedScopes |
| 3402 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3403 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3404 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3405 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3406 | if (mService != null) { |
| 3407 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3408 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3409 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3410 | } catch (CertificateException e) { |
| 3411 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3412 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3413 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3414 | } |
| 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3419 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3420 | * If a user has installed any certificates by other means than device policy these will be |
| 3421 | * included too. |
| 3422 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3423 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3424 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3425 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3426 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3427 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3428 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3429 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3430 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3431 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3432 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3433 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3434 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3435 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3436 | for (String alias : certStore.userAliases()) { |
| 3437 | try { |
| 3438 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3439 | } catch (CertificateException ce) { |
| 3440 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3441 | } |
| 3442 | } |
| 3443 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3444 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3445 | } |
| 3446 | } |
| 3447 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3451 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3452 | * means other than device policy will also be removed, except for system CA certificates. |
| 3453 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3454 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3455 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3456 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3457 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3458 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3459 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3460 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3461 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3462 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3463 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3464 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3465 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3466 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | /** |
| 3472 | * Returns whether this certificate is installed as a trusted CA. |
| 3473 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3474 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3475 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3476 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3477 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3478 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3479 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3480 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3481 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3482 | if (mService != null) { |
| 3483 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3484 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3485 | return getCaCertAlias(certBuffer) != null; |
| 3486 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3487 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3488 | } catch (CertificateException ce) { |
| 3489 | Log.w(TAG, "Could not parse certificate", ce); |
| 3490 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3491 | } |
| 3492 | return false; |
| 3493 | } |
| 3494 | |
| 3495 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3496 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3497 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3498 | * the certificate and use the private key, given direct user approval. |
| 3499 | * |
| 3500 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3501 | * direct user approval. This is for security - should a certificate installer become |
| 3502 | * compromised, certificates it had already installed will be protected. |
| 3503 | * |
| 3504 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3505 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3506 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3507 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3508 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3509 | * @param privKey The private key to install. |
| 3510 | * @param cert The certificate to install. |
| 3511 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3512 | * with that alias already exists, it will be overwritten. |
| 3513 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3514 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3515 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3516 | * @see #setDelegatedScopes |
| 3517 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3518 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3519 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3520 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3521 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | /** |
| 3525 | * 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] | 3526 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3527 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3528 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3529 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3530 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3531 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3532 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3533 | * |
| 3534 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3535 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3536 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3537 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3538 | * certificate and include the chain of trust in order. This will be returned by |
| 3539 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3540 | * @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] | 3541 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3542 | * @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] | 3543 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3544 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3545 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3546 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3547 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3548 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3549 | * @see #setDelegatedScopes |
| 3550 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3551 | */ |
| 3552 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3553 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3554 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3555 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3556 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3557 | byte[] pemChain = null; |
| 3558 | if (certs.length > 1) { |
| 3559 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3560 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3561 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3562 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3563 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3564 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3565 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3566 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3567 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3568 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3569 | } catch (CertificateException | IOException e) { |
| 3570 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3571 | } |
| 3572 | return false; |
| 3573 | } |
| 3574 | |
| 3575 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3576 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3577 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3578 | * |
| 3579 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3580 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3581 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3582 | * @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] | 3583 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3584 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3585 | * @see #setDelegatedScopes |
| 3586 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3587 | */ |
| 3588 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3589 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3590 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3591 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3592 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3593 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3594 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3598 | * @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] | 3599 | * doesn't exist. |
| 3600 | */ |
| 3601 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3602 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3603 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3604 | new ByteArrayInputStream(certBuffer)); |
| 3605 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3606 | } |
| 3607 | |
| 3608 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3609 | * 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] | 3610 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3611 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3612 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3613 | * <p> |
| 3614 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3615 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3616 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3617 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3618 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3619 | * 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] | 3620 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3621 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3622 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3623 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3624 | * @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] | 3625 | * access. If {@code null} is given the current package will be cleared. |
| 3626 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3627 | * |
| 3628 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 3629 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3630 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3631 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3632 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3633 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3634 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3635 | if (mService != null) { |
| 3636 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3637 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3638 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3639 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3640 | } |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3645 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3646 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3647 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3648 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3649 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3650 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3651 | * none is set. |
| 3652 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3653 | * |
| 3654 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3655 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3656 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3657 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3658 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3659 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3660 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3661 | if (mService != null) { |
| 3662 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3663 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3664 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3665 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3666 | } |
| 3667 | } |
| 3668 | return null; |
| 3669 | } |
| 3670 | |
| 3671 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3672 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3673 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3674 | * constants. |
| 3675 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3676 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 3677 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 3678 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 3679 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 3680 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3681 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3682 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3683 | * {@code delegatePackage}. |
| 3684 | * |
| 3685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3686 | * @param delegatePackage The package name of the app which will be given access. |
| 3687 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3688 | * {@code delegatedPackage}. |
| 3689 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3690 | */ |
| 3691 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3692 | @NonNull List<String> scopes) { |
| 3693 | throwIfParentInstance("setDelegatedScopes"); |
| 3694 | if (mService != null) { |
| 3695 | try { |
| 3696 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 3697 | } catch (RemoteException e) { |
| 3698 | throw e.rethrowFromSystemServer(); |
| 3699 | } |
| 3700 | } |
| 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 3705 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 3706 | * passing {@code null} for {@code admin} and their own package name as |
| 3707 | * {@code delegatedPackage}. |
| 3708 | * |
| 3709 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3710 | * {@code null} if the caller is {@code delegatedPackage}. |
| 3711 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 3712 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 3713 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3714 | */ |
| 3715 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3716 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3717 | @NonNull String delegatedPackage) { |
| 3718 | throwIfParentInstance("getDelegatedScopes"); |
| 3719 | if (mService != null) { |
| 3720 | try { |
| 3721 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 3722 | } catch (RemoteException e) { |
| 3723 | throw e.rethrowFromSystemServer(); |
| 3724 | } |
| 3725 | } |
| 3726 | return null; |
| 3727 | } |
| 3728 | |
| 3729 | /** |
| 3730 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 3731 | * granted a delegation scope. |
| 3732 | * |
| 3733 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3734 | * @param delegationScope The scope whose delegates should be retrieved. |
| 3735 | * @return A list of package names of the current delegated packages for |
| 3736 | {@code delegationScope}. |
| 3737 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3738 | */ |
| 3739 | @Nullable |
| 3740 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 3741 | @NonNull String delegationScope) { |
| 3742 | throwIfParentInstance("getDelegatePackages"); |
| 3743 | if (mService != null) { |
| 3744 | try { |
| 3745 | return mService.getDelegatePackages(admin, delegationScope); |
| 3746 | } catch (RemoteException e) { |
| 3747 | throw e.rethrowFromSystemServer(); |
| 3748 | } |
| 3749 | } |
| 3750 | return null; |
| 3751 | } |
| 3752 | |
| 3753 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3754 | * 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] | 3755 | * specific application for the current user. |
| 3756 | * |
| 3757 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3758 | * TODO: delete once there are no longer any live references. |
| 3759 | * @hide |
| 3760 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3761 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3762 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3763 | throws NameNotFoundException, UnsupportedOperationException { |
| 3764 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3765 | } |
| 3766 | |
| 3767 | /** |
| 3768 | * 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] | 3769 | * specific application for the current user. This connection is automatically granted and |
| 3770 | * persisted after a reboot. |
| 3771 | * <p> |
| 3772 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3773 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3774 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3775 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3776 | * @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] | 3777 | * remove an existing always-on VPN configuration. |
| 3778 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3779 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3780 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3781 | * @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] | 3782 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3783 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3784 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3785 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3786 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3787 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3788 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3789 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3790 | if (mService != null) { |
| 3791 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3792 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3793 | throw new NameNotFoundException(vpnPackage); |
| 3794 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3795 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3796 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3797 | } |
| 3798 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * 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] | 3803 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3804 | * 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] | 3805 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3806 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3807 | * is set. |
| 3808 | * @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] | 3809 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3810 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3811 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3812 | if (mService != null) { |
| 3813 | try { |
| 3814 | return mService.getAlwaysOnVpnPackage(admin); |
| 3815 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3816 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3817 | } |
| 3818 | } |
| 3819 | return null; |
| 3820 | } |
| 3821 | |
| 3822 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3823 | * Called by an application that is administering the device to disable all cameras on the |
| 3824 | * device, for this user. After setting this, no applications running as this user will be able |
| 3825 | * to access any cameras on the device. |
| 3826 | * <p> |
| 3827 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3828 | * <p> |
| 3829 | * The calling device admin must have requested |
| 3830 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3831 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3832 | * |
| 3833 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3834 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3835 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3836 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3837 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3838 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3839 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3840 | if (mService != null) { |
| 3841 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3842 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3843 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3844 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3845 | } |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3850 | * 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] | 3851 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3852 | * @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] | 3853 | * have disabled the camera |
| 3854 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3855 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3856 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3857 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3861 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3862 | if (mService != null) { |
| 3863 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3864 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3865 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3866 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3867 | } |
| 3868 | } |
| 3869 | return false; |
| 3870 | } |
| 3871 | |
| 3872 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3873 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3874 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 3875 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 3876 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 3877 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3878 | * |
| 3879 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3880 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3881 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3882 | * bugreport is still running or waiting for the user to share or decline) |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 3883 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 3884 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3885 | */ |
| 3886 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3887 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3888 | if (mService != null) { |
| 3889 | try { |
| 3890 | return mService.requestBugreport(admin); |
| 3891 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3892 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3893 | } |
| 3894 | } |
| 3895 | return false; |
| 3896 | } |
| 3897 | |
| 3898 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3899 | * Determine whether or not creating a guest user has been disabled for the device |
| 3900 | * |
| 3901 | * @hide |
| 3902 | */ |
| 3903 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3904 | // Currently guest users can always be created if multi-user is enabled |
| 3905 | // TODO introduce a policy for guest user creation |
| 3906 | return false; |
| 3907 | } |
| 3908 | |
| 3909 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3910 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3911 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3912 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3913 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3914 | * <p> |
| 3915 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3916 | * exception will be thrown. |
| 3917 | * <p> |
| 3918 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3919 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3920 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3921 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3922 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3923 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3924 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3925 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3926 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3927 | if (mService != null) { |
| 3928 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3929 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3930 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3931 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3937 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3938 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3939 | * @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] | 3940 | * have disabled screen capture. |
| 3941 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3942 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3943 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3944 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3948 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3949 | if (mService != null) { |
| 3950 | try { |
| 3951 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3952 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3953 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3954 | } |
| 3955 | } |
| 3956 | return false; |
| 3957 | } |
| 3958 | |
| 3959 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 3960 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 3961 | * required, no user will be able set the date and time and network date and time will be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3962 | * <p> |
| 3963 | * Note: if auto time is required the user can still manually set the time zone. |
| 3964 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 3965 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3966 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3967 | * |
| 3968 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3969 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3970 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3971 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3972 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3973 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3974 | if (mService != null) { |
| 3975 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3976 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3977 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3978 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3979 | } |
| 3980 | } |
| 3981 | } |
| 3982 | |
| 3983 | /** |
| 3984 | * @return true if auto time is required. |
| 3985 | */ |
| 3986 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3987 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3988 | if (mService != null) { |
| 3989 | try { |
| 3990 | return mService.getAutoTimeRequired(); |
| 3991 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3992 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3993 | } |
| 3994 | } |
| 3995 | return false; |
| 3996 | } |
| 3997 | |
| 3998 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3999 | * 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] | 4000 | * <p> |
| 4001 | * The system user is exempt from this policy - it is never ephemeral. |
| 4002 | * <p> |
| 4003 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4004 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4005 | * |
| 4006 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4007 | * @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] | 4008 | * subsequently created users will be ephemeral. |
| 4009 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4010 | * @hide |
| 4011 | */ |
| 4012 | public void setForceEphemeralUsers( |
| 4013 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4014 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4015 | if (mService != null) { |
| 4016 | try { |
| 4017 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 4018 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4019 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4020 | } |
| 4021 | } |
| 4022 | } |
| 4023 | |
| 4024 | /** |
| 4025 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4026 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4027 | * @hide |
| 4028 | */ |
| 4029 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4030 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4031 | if (mService != null) { |
| 4032 | try { |
| 4033 | return mService.getForceEphemeralUsers(admin); |
| 4034 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4035 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4036 | } |
| 4037 | } |
| 4038 | return false; |
| 4039 | } |
| 4040 | |
| 4041 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4042 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4043 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4044 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4045 | * <p> |
| 4046 | * The calling device admin must have requested |
| 4047 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4048 | * if it has not, a security exception will be thrown. |
| 4049 | * <p> |
| 4050 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4051 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4052 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4053 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4054 | * <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] | 4055 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4056 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4057 | * there is one, or the parent user otherwise. |
| 4058 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4059 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4060 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4061 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4062 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4063 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4064 | * profile. |
| 4065 | * <p> |
| 4066 | * Requests to disable other features on a managed profile will be ignored. |
| 4067 | * <p> |
| 4068 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4069 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4070 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4071 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4072 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4073 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4074 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4075 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4076 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4077 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4078 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4079 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4080 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4081 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4082 | if (mService != null) { |
| 4083 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4084 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4085 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4086 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4092 | * 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] | 4093 | * 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] | 4094 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4095 | * |
| 4096 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4097 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4098 | * restrictions on the parent profile. |
| 4099 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4100 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4101 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4102 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4103 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4104 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4105 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4106 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4110 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4111 | if (mService != null) { |
| 4112 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4113 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4114 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4115 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4116 | } |
| 4117 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4118 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4122 | * @hide |
| 4123 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4124 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4125 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4126 | if (mService != null) { |
| 4127 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4128 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4129 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4130 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4131 | } |
| 4132 | } |
| 4133 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4134 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4135 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4136 | * @hide |
| 4137 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4138 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4139 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4143 | * @hide |
| 4144 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4145 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4146 | if (mService != null) { |
| 4147 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4148 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4149 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4150 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4151 | } |
| 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | /** |
| 4156 | * @hide |
| 4157 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4158 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4159 | if (mService != null) { |
| 4160 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4161 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4162 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4163 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4164 | } |
| 4165 | } |
| 4166 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4167 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4168 | /** |
| 4169 | * @hide |
| 4170 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4171 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4172 | if (mService != null) { |
| 4173 | try { |
| 4174 | mService.reportPasswordChanged(userId); |
| 4175 | } catch (RemoteException e) { |
| 4176 | throw e.rethrowFromSystemServer(); |
| 4177 | } |
| 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | /** |
| 4182 | * @hide |
| 4183 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4184 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4185 | if (mService != null) { |
| 4186 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4187 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4188 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4189 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4190 | } |
| 4191 | } |
| 4192 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4193 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4194 | /** |
| 4195 | * @hide |
| 4196 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4197 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4198 | if (mService != null) { |
| 4199 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4200 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4201 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4202 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4206 | |
| 4207 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4208 | * @hide |
| 4209 | */ |
| 4210 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4211 | if (mService != null) { |
| 4212 | try { |
| 4213 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4214 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4215 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | /** |
| 4221 | * @hide |
| 4222 | */ |
| 4223 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4224 | if (mService != null) { |
| 4225 | try { |
| 4226 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4227 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4228 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4229 | } |
| 4230 | } |
| 4231 | } |
| 4232 | |
| 4233 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4234 | * Should be called when keyguard has been dismissed. |
| 4235 | * @hide |
| 4236 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4237 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4238 | if (mService != null) { |
| 4239 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4240 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4241 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4242 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4243 | } |
| 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | /** |
| 4248 | * Should be called when keyguard view has been shown to the user. |
| 4249 | * @hide |
| 4250 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4251 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4252 | if (mService != null) { |
| 4253 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4254 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4255 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4256 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4257 | } |
| 4258 | } |
| 4259 | } |
| 4260 | |
| 4261 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4262 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4263 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4264 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4265 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4266 | * @return whether the package was successfully registered as the device owner. |
| 4267 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4268 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4269 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4270 | public boolean setDeviceOwner(ComponentName who) { |
| 4271 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | /** |
| 4275 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4276 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4277 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4278 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | /** |
| 4282 | * @hide |
| 4283 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4284 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4285 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | /** |
| 4289 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4290 | * Sets the given package as the device owner. The package must already be installed. There |
| 4291 | * must not already be a device owner. |
| 4292 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4293 | * this method. |
| 4294 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4295 | * 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] | 4296 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4297 | * @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] | 4298 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4299 | * @return whether the package was successfully registered as the device owner. |
| 4300 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4301 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4302 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4303 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4304 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4305 | if (mService != null) { |
| 4306 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4307 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4308 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4309 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4310 | } |
| 4311 | } |
| 4312 | return false; |
| 4313 | } |
| 4314 | |
| 4315 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4316 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4317 | * 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] | 4318 | * 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] | 4319 | * package is currently registered as the device owner app, pass in the package name from |
| 4320 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4321 | * 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] | 4322 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4323 | * the setup process. |
| 4324 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4325 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4326 | * @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] | 4327 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4328 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4329 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4330 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4331 | } |
| 4332 | |
| 4333 | /** |
| 4334 | * @return true if a package is registered as device owner, only when it's running on the |
| 4335 | * calling user. |
| 4336 | * |
| 4337 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4338 | * @hide |
| 4339 | */ |
| 4340 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4341 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4342 | } |
| 4343 | |
| 4344 | /** |
| 4345 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4346 | * user. |
| 4347 | * |
| 4348 | * <p>Requires the MANAGE_USERS permission. |
| 4349 | * |
| 4350 | * @hide |
| 4351 | */ |
| 4352 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4353 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4354 | } |
| 4355 | |
| 4356 | /** |
| 4357 | * @return device owner component name, only when it's running on the calling user. |
| 4358 | * |
| 4359 | * @hide |
| 4360 | */ |
| 4361 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4362 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4363 | } |
| 4364 | |
| 4365 | /** |
| 4366 | * @return device owner component name, even if it's running on a different user. |
| 4367 | * |
| 4368 | * <p>Requires the MANAGE_USERS permission. |
| 4369 | * |
| 4370 | * @hide |
| 4371 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4372 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4373 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4374 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4375 | } |
| 4376 | |
| 4377 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4378 | if (packageName == null) { |
| 4379 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4380 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4381 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4382 | if (deviceOwner == null) { |
| 4383 | return false; |
| 4384 | } |
| 4385 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4386 | } |
| 4387 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4388 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4389 | if (mService != null) { |
| 4390 | try { |
| 4391 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4392 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4393 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4394 | } |
| 4395 | } |
| 4396 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4397 | } |
| 4398 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4399 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4400 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4401 | * no device owner. |
| 4402 | * |
| 4403 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4404 | * |
| 4405 | * @hide |
| 4406 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4407 | public int getDeviceOwnerUserId() { |
| 4408 | if (mService != null) { |
| 4409 | try { |
| 4410 | return mService.getDeviceOwnerUserId(); |
| 4411 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4412 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4413 | } |
| 4414 | } |
| 4415 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4419 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4420 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 4421 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4422 | * |
| 4423 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4424 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4425 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4426 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4427 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4428 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4429 | if (mService != null) { |
| 4430 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4431 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4432 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4433 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4434 | } |
| 4435 | } |
| 4436 | } |
| 4437 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4438 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4439 | * Returns the device owner package name, only if it's running on the calling user. |
| 4440 | * |
| 4441 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4442 | * |
| 4443 | * @hide |
| 4444 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4445 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4446 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4447 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4448 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4449 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4453 | * 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] | 4454 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4455 | * @return whether the device is managed by a Device Owner. |
| 4456 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4457 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4458 | * |
| 4459 | * @hide |
| 4460 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4461 | @SystemApi |
| 4462 | @TestApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4463 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4464 | try { |
| 4465 | return mService.hasDeviceOwner(); |
| 4466 | } catch (RemoteException re) { |
| 4467 | throw re.rethrowFromSystemServer(); |
| 4468 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | /** |
| 4472 | * Returns the device owner name. Note this method *will* return the device owner |
| 4473 | * name when it's running on a different user. |
| 4474 | * |
| 4475 | * <p>Requires the MANAGE_USERS permission. |
| 4476 | * |
| 4477 | * @hide |
| 4478 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4479 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4480 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4481 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4482 | if (mService != null) { |
| 4483 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4484 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4485 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4486 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4487 | } |
| 4488 | } |
| 4489 | return null; |
| 4490 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4491 | |
| 4492 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4493 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4494 | * @deprecated Do not use |
| 4495 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4496 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4497 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4498 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4499 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4500 | return null; |
| 4501 | } |
| 4502 | |
| 4503 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4504 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4505 | * @deprecated Do not use |
| 4506 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4507 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4508 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4509 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4510 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4511 | return null; |
| 4512 | } |
| 4513 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4514 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4515 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4516 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4517 | * Sets the given component as an active admin and registers the package as the profile |
| 4518 | * owner for this user. The package must already be installed and there shouldn't be |
| 4519 | * an existing profile owner registered for this user. Also, this method must be called |
| 4520 | * before the user setup has been completed. |
| 4521 | * <p> |
| 4522 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4523 | * MANAGE_DEVICE_ADMINS permission. |
| 4524 | * @param admin The component to register as an active admin and profile owner. |
| 4525 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4526 | * @return whether the admin was successfully registered as the profile owner. |
| 4527 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4528 | * the user has already been set up. |
| 4529 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4530 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4531 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4532 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4533 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4534 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4535 | if (mService != null) { |
| 4536 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4537 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4538 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4539 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4540 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4541 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4542 | } |
| 4543 | } |
| 4544 | return false; |
| 4545 | } |
| 4546 | |
| 4547 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4548 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 4549 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 4550 | * will be thrown. |
| 4551 | * <p> |
| 4552 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4553 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4554 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4555 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4556 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4557 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4558 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4559 | if (mService != null) { |
| 4560 | try { |
| 4561 | mService.clearProfileOwner(admin); |
| 4562 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4563 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4564 | } |
| 4565 | } |
| 4566 | } |
| 4567 | |
| 4568 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4569 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4570 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4571 | */ |
| 4572 | public boolean hasUserSetupCompleted() { |
| 4573 | if (mService != null) { |
| 4574 | try { |
| 4575 | return mService.hasUserSetupCompleted(); |
| 4576 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4577 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4578 | } |
| 4579 | } |
| 4580 | return true; |
| 4581 | } |
| 4582 | |
| 4583 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4584 | * @hide |
| 4585 | * 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] | 4586 | * already be installed. There must not already be a profile owner for this user. |
| 4587 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4588 | * this method. |
| 4589 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4590 | * - the caller is SYSTEM_UID. |
| 4591 | * - 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] | 4592 | * @param admin the component name to be registered as profile owner. |
| 4593 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4594 | * @param userHandle the userId to set the profile owner for. |
| 4595 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4596 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4597 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4598 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4599 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4600 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4601 | if (mService != null) { |
| 4602 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4603 | if (ownerName == null) { |
| 4604 | ownerName = ""; |
| 4605 | } |
| 4606 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4607 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4608 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4609 | } |
| 4610 | } |
| 4611 | return false; |
| 4612 | } |
| 4613 | |
| 4614 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4615 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4616 | * <p> |
| 4617 | * 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] | 4618 | * 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] | 4619 | * <p> |
| 4620 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4621 | * will be blank and the user will not be allowed to change it. |
| 4622 | * <p> |
| 4623 | * 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] | 4624 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4625 | * and set a new version of this string accordingly. |
| 4626 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4627 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4628 | * @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] | 4629 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4630 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4631 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4632 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4633 | if (mService != null) { |
| 4634 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4635 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4636 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4637 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4638 | } |
| 4639 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * @return The device owner information. If it is not set returns {@code null}. |
| 4644 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4645 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4646 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4647 | if (mService != null) { |
| 4648 | try { |
| 4649 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4650 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4651 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4652 | } |
| 4653 | } |
| 4654 | return null; |
| 4655 | } |
| 4656 | |
| 4657 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4658 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4659 | * called by a device owner, profile owner, or by a delegate given the |
| 4660 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4661 | * <p> |
| 4662 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4663 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4664 | * device. |
| 4665 | * <p> |
| 4666 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4667 | * 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] | 4668 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4669 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4670 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4671 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4672 | * @param packageNames The package names to suspend or unsuspend. |
| 4673 | * @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] | 4674 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4675 | * @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] | 4676 | * this method. |
| 4677 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4678 | * @see #setDelegatedScopes |
| 4679 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4680 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4681 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4682 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4683 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4684 | if (mService != null) { |
| 4685 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4686 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 4687 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4688 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4689 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4690 | } |
| 4691 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4692 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4696 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 4697 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 4698 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4699 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4700 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4701 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4702 | * @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] | 4703 | * @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] | 4704 | * suspended, could not be found or an error occurred. |
| 4705 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4706 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4707 | * @see #setDelegatedScopes |
| 4708 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4709 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4710 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4711 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4712 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4713 | if (mService != null) { |
| 4714 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4715 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4716 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4717 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4718 | } catch (IllegalArgumentException ex) { |
| 4719 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4720 | } |
| 4721 | } |
| 4722 | return false; |
| 4723 | } |
| 4724 | |
| 4725 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4726 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4727 | * be used. Only the profile owner can call this. |
| 4728 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4729 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4730 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4731 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4732 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4733 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4734 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4735 | if (mService != null) { |
| 4736 | try { |
| 4737 | mService.setProfileEnabled(admin); |
| 4738 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4739 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4740 | } |
| 4741 | } |
| 4742 | } |
| 4743 | |
| 4744 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4745 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4746 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4747 | * 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] | 4748 | * |
| 4749 | * @see #isProfileOwnerApp |
| 4750 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4751 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4752 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4753 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4754 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4755 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4756 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4757 | if (mService != null) { |
| 4758 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4759 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4760 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4761 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4762 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4763 | } |
| 4764 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4765 | |
| 4766 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4767 | * 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] | 4768 | * 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] | 4769 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4770 | * |
| 4771 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4772 | * @return Whether or not the package is registered as the profile owner. |
| 4773 | */ |
| 4774 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4775 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4776 | if (mService != null) { |
| 4777 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4778 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4779 | return profileOwner != null |
| 4780 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4781 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4782 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | return false; |
| 4786 | } |
| 4787 | |
| 4788 | /** |
| 4789 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4790 | * @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] | 4791 | * owner has been set for that user. |
| 4792 | * @throws IllegalArgumentException if the userId is invalid. |
| 4793 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4794 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4795 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4796 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4797 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4798 | } |
| 4799 | |
| 4800 | /** |
| 4801 | * @see #getProfileOwner() |
| 4802 | * @hide |
| 4803 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4804 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4805 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4806 | if (mService != null) { |
| 4807 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4808 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4809 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4810 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4811 | } |
| 4812 | } |
| 4813 | return null; |
| 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4818 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4819 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4820 | * @throws IllegalArgumentException if the userId is invalid. |
| 4821 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4822 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4823 | if (mService != null) { |
| 4824 | try { |
| 4825 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4826 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4827 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4828 | } |
| 4829 | } |
| 4830 | return null; |
| 4831 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4832 | |
| 4833 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4834 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4835 | * @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] | 4836 | * @return the human readable name of the organisation associated with this profile owner or |
| 4837 | * null if one is not set. |
| 4838 | * @throws IllegalArgumentException if the userId is invalid. |
| 4839 | */ |
| 4840 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4841 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4842 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4843 | if (mService != null) { |
| 4844 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 4845 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4846 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4847 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4848 | } |
| 4849 | } |
| 4850 | return null; |
| 4851 | } |
| 4852 | |
| 4853 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4854 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 4855 | * 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] | 4856 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 4857 | * intent preferences are reset. |
| 4858 | * <p> |
| 4859 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 4860 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 4861 | * the filter. |
| 4862 | * <p> |
| 4863 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 4864 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4865 | * |
| 4866 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4867 | * @param filter The IntentFilter for which a default handler is added. |
| 4868 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4869 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4870 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4871 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 4872 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4873 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4874 | if (mService != null) { |
| 4875 | try { |
| 4876 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4877 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4878 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4879 | } |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | /** |
| 4884 | * 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] | 4885 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4886 | * <p> |
| 4887 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4888 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4889 | * |
| 4890 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4891 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4892 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4893 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4894 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4895 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4896 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4897 | if (mService != null) { |
| 4898 | try { |
| 4899 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4900 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4901 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4902 | } |
| 4903 | } |
| 4904 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4905 | |
| 4906 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4907 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4908 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4909 | * {@link #getApplicationRestrictions}. |
| 4910 | * <p> |
| 4911 | * This permission is persistent until it is later cleared by calling this method with a |
| 4912 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4913 | * <p> |
| 4914 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4915 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4916 | * |
| 4917 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4918 | * @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] | 4919 | * APIs. If {@code null} is given the current package will be cleared. |
| 4920 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4921 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4922 | * |
| 4923 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 4924 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4925 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4926 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4927 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4928 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4929 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4930 | if (mService != null) { |
| 4931 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4932 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4933 | throw new NameNotFoundException(packageName); |
| 4934 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4935 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4936 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4937 | } |
| 4938 | } |
| 4939 | } |
| 4940 | |
| 4941 | /** |
| 4942 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4943 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 4944 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4945 | * |
| 4946 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4947 | * @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] | 4948 | * {@code null} if none is set. |
| 4949 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4950 | * |
| 4951 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 4952 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4953 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4954 | @Deprecated |
| 4955 | @Nullable |
| 4956 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4957 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4958 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4959 | if (mService != null) { |
| 4960 | try { |
| 4961 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4962 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4963 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4964 | } |
| 4965 | } |
| 4966 | return null; |
| 4967 | } |
| 4968 | |
| 4969 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4970 | * Called by any application to find out whether it has been granted permission via |
| 4971 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4972 | * for the calling user. |
| 4973 | * |
| 4974 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4975 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4976 | * |
| 4977 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 4978 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4979 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4980 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4981 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4982 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4983 | if (mService != null) { |
| 4984 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4985 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 4986 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4987 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4988 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4989 | } |
| 4990 | } |
| 4991 | return false; |
| 4992 | } |
| 4993 | |
| 4994 | /** |
| 4995 | * 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] | 4996 | * <p> |
| 4997 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4998 | * application restrictions via {@link #setDelegatedScopes} with the |
| 4999 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5000 | * <p> |
| 5001 | * 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] | 5002 | * <ul> |
| 5003 | * <li>{@code boolean} |
| 5004 | * <li>{@code int} |
| 5005 | * <li>{@code String} or {@code String[]} |
| 5006 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5007 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5008 | * <p> |
| 5009 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5010 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5011 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5012 | * <p> |
| 5013 | * The application restrictions are only made visible to the target application via |
| 5014 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5015 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5016 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5017 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5018 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5019 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5020 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5021 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5022 | * @param packageName The name of the package to update restricted settings for. |
| 5023 | * @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] | 5024 | * set of active restrictions. |
| 5025 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5026 | * @see #setDelegatedScopes |
| 5027 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5028 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5029 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5030 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5031 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5032 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5033 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5034 | if (mService != null) { |
| 5035 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5036 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5037 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5038 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5039 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5040 | } |
| 5041 | } |
| 5042 | } |
| 5043 | |
| 5044 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5045 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 5046 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5047 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5048 | * {@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] | 5049 | * <p> |
| 5050 | * The calling device admin must have requested |
| 5051 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5052 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5053 | * <p> |
| 5054 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5055 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5056 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5057 | * |
| 5058 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5059 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5060 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5061 | * strictly disabled according to the state of the |
| 5062 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5063 | * <p> |
| 5064 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5065 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5066 | * device admins. |
| 5067 | * <p> |
| 5068 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5069 | * parameters. |
| 5070 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5071 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5072 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5073 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5074 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5075 | if (mService != null) { |
| 5076 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5077 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5078 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5079 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5080 | } |
| 5081 | } |
| 5082 | } |
| 5083 | |
| 5084 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5085 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5086 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5087 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5088 | * <p> |
| 5089 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5090 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5091 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5092 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5093 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5094 | * this function returns a list of configurations for all admins that declare |
| 5095 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5096 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5097 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5098 | * 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] | 5099 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5100 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5101 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5102 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5103 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5104 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5108 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5109 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5110 | if (mService != null) { |
| 5111 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5112 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5113 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5114 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5115 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5116 | } |
| 5117 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5118 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5122 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5123 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5124 | * <p> |
| 5125 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5126 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5127 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5128 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5129 | * @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] | 5130 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5131 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5132 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5133 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5134 | if (mService != null) { |
| 5135 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5136 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5137 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5138 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5139 | } |
| 5140 | } |
| 5141 | } |
| 5142 | |
| 5143 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5144 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5145 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5146 | * <p> |
| 5147 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5148 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5149 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5150 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5151 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5152 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5153 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5154 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5155 | if (mService != null) { |
| 5156 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5157 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5158 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5159 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5160 | } |
| 5161 | } |
| 5162 | return false; |
| 5163 | } |
| 5164 | |
| 5165 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5166 | * Determine whether or not caller-Id information has been disabled. |
| 5167 | * |
| 5168 | * @param userHandle The user for whom to check the caller-id permission |
| 5169 | * @hide |
| 5170 | */ |
| 5171 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5172 | if (mService != null) { |
| 5173 | try { |
| 5174 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5175 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5176 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5177 | } |
| 5178 | } |
| 5179 | return false; |
| 5180 | } |
| 5181 | |
| 5182 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5183 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5184 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5185 | * <p> |
| 5186 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5187 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5188 | * |
| 5189 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5190 | * @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] | 5191 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5192 | */ |
| 5193 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5194 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5195 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5196 | if (mService != null) { |
| 5197 | try { |
| 5198 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5199 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5200 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | } |
| 5204 | |
| 5205 | /** |
| 5206 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5207 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5208 | * <p> |
| 5209 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5210 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5211 | * |
| 5212 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5213 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5214 | */ |
| 5215 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5216 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5217 | if (mService != null) { |
| 5218 | try { |
| 5219 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 5220 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5221 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5222 | } |
| 5223 | } |
| 5224 | return false; |
| 5225 | } |
| 5226 | |
| 5227 | |
| 5228 | /** |
| 5229 | * Determine whether or not contacts search has been disabled. |
| 5230 | * |
| 5231 | * @param userHandle The user for whom to check the contacts search permission |
| 5232 | * @hide |
| 5233 | */ |
| 5234 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5235 | if (mService != null) { |
| 5236 | try { |
| 5237 | return mService |
| 5238 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5239 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5240 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5241 | } |
| 5242 | } |
| 5243 | return false; |
| 5244 | } |
| 5245 | |
| 5246 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5247 | * 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] | 5248 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5249 | * @hide |
| 5250 | */ |
| 5251 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5252 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5253 | if (mService != null) { |
| 5254 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5255 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5256 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5257 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5258 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5259 | } |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5264 | * 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] | 5265 | * @hide |
| 5266 | */ |
| 5267 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5268 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5269 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5270 | originalIntent); |
| 5271 | } |
| 5272 | |
| 5273 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5274 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5275 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5276 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5277 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5278 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5279 | * <p> |
| 5280 | * This API works on managed profile only. |
| 5281 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5282 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5283 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5284 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5285 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5286 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5287 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5288 | if (mService != null) { |
| 5289 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5290 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5291 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5292 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5293 | } |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5298 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5299 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5300 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5301 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5302 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5303 | * <p> |
| 5304 | * This API works on managed profile only. |
| 5305 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5306 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5307 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5308 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5309 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5310 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5311 | if (mService != null) { |
| 5312 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5313 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5314 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5315 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | return true; |
| 5319 | } |
| 5320 | |
| 5321 | /** |
| 5322 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5323 | * <p> |
| 5324 | * This API works on managed profile UserHandle only. |
| 5325 | * |
| 5326 | * @param userHandle The user for whom to check the caller-id permission |
| 5327 | * @hide |
| 5328 | */ |
| 5329 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5330 | if (mService != null) { |
| 5331 | try { |
| 5332 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5333 | .getIdentifier()); |
| 5334 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5335 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5336 | } |
| 5337 | } |
| 5338 | return true; |
| 5339 | } |
| 5340 | |
| 5341 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5342 | * 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] | 5343 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5344 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5345 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5346 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5347 | * @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] | 5348 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5349 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5350 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5351 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5352 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5353 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5354 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5355 | if (mService != null) { |
| 5356 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5357 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5358 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5359 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5360 | } |
| 5361 | } |
| 5362 | } |
| 5363 | |
| 5364 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5365 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5366 | * 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] | 5367 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5368 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5369 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5370 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5371 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5372 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5373 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5374 | if (mService != null) { |
| 5375 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5376 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5377 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5378 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5379 | } |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5384 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5385 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5386 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5387 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5388 | * the list and not part of the system can not be enabled by the user. |
| 5389 | * <p> |
| 5390 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5391 | * used, calling with an empty list only allows the builtin system's services. |
| 5392 | * <p> |
| 5393 | * 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] | 5394 | * |
| 5395 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5396 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5397 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5398 | * accessibility services enabled, that are not in the list. |
| 5399 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5400 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5401 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5402 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5403 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5404 | if (mService != null) { |
| 5405 | try { |
| 5406 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5407 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5408 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5409 | } |
| 5410 | } |
| 5411 | return false; |
| 5412 | } |
| 5413 | |
| 5414 | /** |
| 5415 | * 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] | 5416 | * <p> |
| 5417 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5418 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5419 | * |
| 5420 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5421 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5422 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5423 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5424 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5425 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5426 | if (mService != null) { |
| 5427 | try { |
| 5428 | return mService.getPermittedAccessibilityServices(admin); |
| 5429 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5430 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5431 | } |
| 5432 | } |
| 5433 | return null; |
| 5434 | } |
| 5435 | |
| 5436 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5437 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5438 | * |
| 5439 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5440 | * @param packageName Accessibility service package name that needs to be checked. |
| 5441 | * @param userHandle user id the admin is running as. |
| 5442 | * @return true if the accessibility service is permitted, otherwise false. |
| 5443 | * |
| 5444 | * @hide |
| 5445 | */ |
| 5446 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5447 | @NonNull String packageName, int userHandle) { |
| 5448 | if (mService != null) { |
| 5449 | try { |
| 5450 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5451 | userHandle); |
| 5452 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5453 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5454 | } |
| 5455 | } |
| 5456 | return false; |
| 5457 | } |
| 5458 | |
| 5459 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5460 | * Returns the list of accessibility services permitted by the device or profiles |
| 5461 | * owners of this user. |
| 5462 | * |
| 5463 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5464 | * it will contain the intersection of the permitted lists for any device or profile |
| 5465 | * owners that apply to this user. It will also include any system accessibility services. |
| 5466 | * |
| 5467 | * @param userId which user to check for. |
| 5468 | * @return List of accessiblity service package names. |
| 5469 | * @hide |
| 5470 | */ |
| 5471 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5472 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5473 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5474 | if (mService != null) { |
| 5475 | try { |
| 5476 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5477 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5478 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5479 | } |
| 5480 | } |
| 5481 | return null; |
| 5482 | } |
| 5483 | |
| 5484 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5485 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5486 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5487 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5488 | * When zero or more packages have been added, input method that are not in the list and not |
| 5489 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5490 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5491 | * <p> |
| 5492 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5493 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5494 | * <p> |
| 5495 | * 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] | 5496 | * |
| 5497 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5498 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5499 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5500 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5501 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5502 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5503 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5504 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5505 | if (mService != null) { |
| 5506 | try { |
| 5507 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5508 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5509 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5510 | } |
| 5511 | } |
| 5512 | return false; |
| 5513 | } |
| 5514 | |
| 5515 | |
| 5516 | /** |
| 5517 | * 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] | 5518 | * <p> |
| 5519 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5520 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5521 | * |
| 5522 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5523 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5524 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5525 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5526 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5527 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5528 | if (mService != null) { |
| 5529 | try { |
| 5530 | return mService.getPermittedInputMethods(admin); |
| 5531 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5532 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5533 | } |
| 5534 | } |
| 5535 | return null; |
| 5536 | } |
| 5537 | |
| 5538 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5539 | * Called by the system to check if a specific input method is disabled by admin. |
| 5540 | * |
| 5541 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5542 | * @param packageName Input method package name that needs to be checked. |
| 5543 | * @param userHandle user id the admin is running as. |
| 5544 | * @return true if the input method is permitted, otherwise false. |
| 5545 | * |
| 5546 | * @hide |
| 5547 | */ |
| 5548 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5549 | @NonNull String packageName, int userHandle) { |
| 5550 | if (mService != null) { |
| 5551 | try { |
| 5552 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5553 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5554 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5555 | } |
| 5556 | } |
| 5557 | return false; |
| 5558 | } |
| 5559 | |
| 5560 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5561 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5562 | * 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] | 5563 | * |
| 5564 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5565 | * it will contain the intersection of the permitted lists for any device or profile |
| 5566 | * owners that apply to this user. It will also include any system input methods. |
| 5567 | * |
| 5568 | * @return List of input method package names. |
| 5569 | * @hide |
| 5570 | */ |
| 5571 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5572 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5573 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5574 | if (mService != null) { |
| 5575 | try { |
| 5576 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5577 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5578 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5579 | } |
| 5580 | } |
| 5581 | return null; |
| 5582 | } |
| 5583 | |
| 5584 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5585 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 5586 | * function can be called by a device owner or by a delegate given the |
| 5587 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 5588 | * <p> |
| 5589 | * Please note that packages returned in this method are not automatically pre-cached. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5590 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5591 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5592 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5593 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5594 | * @see #setDelegatedScopes |
| 5595 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5596 | * @hide |
| 5597 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5598 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5599 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5600 | if (mService != null) { |
| 5601 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5602 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5603 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5604 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5605 | } |
| 5606 | } |
| 5607 | return null; |
| 5608 | } |
| 5609 | |
| 5610 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5611 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 5612 | * function can be called by a device owner or by a delegate given the |
| 5613 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5614 | * |
| 5615 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5616 | * automatically pre-cached.</p> |
| 5617 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5618 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5619 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5620 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5621 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5622 | * @see #setDelegatedScopes |
| 5623 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5624 | * @hide |
| 5625 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5626 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5627 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5628 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5629 | if (mService != null) { |
| 5630 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5631 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5632 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5633 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5634 | } |
| 5635 | } |
| 5636 | } |
| 5637 | |
| 5638 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5639 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5640 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5641 | * created. If you need to persist an identifier for this user, use |
| 5642 | * {@link UserManager#getSerialNumberForUser}. |
| 5643 | * |
| 5644 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5645 | * @param name the user's name |
| 5646 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5647 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5648 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5649 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5650 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5651 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5652 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5653 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5654 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5655 | return null; |
| 5656 | } |
| 5657 | |
| 5658 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5659 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5660 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5661 | * created. If you need to persist an identifier for this user, use |
| 5662 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5663 | * immediately. |
| 5664 | * |
| 5665 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5666 | * as registered as an active admin on the new user. The profile owner package will be |
| 5667 | * installed on the new user if it already is installed on the device. |
| 5668 | * |
| 5669 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5670 | * profileOwnerComponent when onEnable is called. |
| 5671 | * |
| 5672 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5673 | * @param name the user's name |
| 5674 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5675 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5676 | * the user. |
| 5677 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5678 | * on the new user. |
| 5679 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5680 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5681 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5682 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5683 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5684 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5685 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5686 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5687 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5688 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5689 | return null; |
| 5690 | } |
| 5691 | |
| 5692 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5693 | * 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] | 5694 | */ |
| 5695 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5696 | |
| 5697 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5698 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5699 | * ephemeral. |
| 5700 | * @hide |
| 5701 | */ |
| 5702 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5703 | |
| 5704 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5705 | * Called by a device owner to create a user with the specified name and a given component of |
| 5706 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5707 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5708 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5709 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5710 | * <p> |
| 5711 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5712 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5713 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5714 | * on the new user. |
| 5715 | * <p> |
| 5716 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5717 | * 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] | 5718 | * |
| 5719 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5720 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5721 | * @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] | 5722 | * same package as admin, otherwise no user is created and an |
| 5723 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5724 | * @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] | 5725 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5726 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5727 | * @see UserHandle |
| 5728 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5729 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5730 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5731 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5732 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5733 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5734 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5735 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5736 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5737 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5738 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5739 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5740 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5741 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5745 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5746 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5747 | * |
| 5748 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5749 | * @param userHandle the user to remove. |
| 5750 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5751 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5752 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5753 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5754 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5755 | try { |
| 5756 | return mService.removeUser(admin, userHandle); |
| 5757 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5758 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5763 | * Called by a device owner to switch the specified user to the foreground. |
| 5764 | * |
| 5765 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5766 | * @param userHandle the user to switch to; null will switch to primary. |
| 5767 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5768 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5769 | * @see Intent#ACTION_USER_FOREGROUND |
| 5770 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5771 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5772 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5773 | try { |
| 5774 | return mService.switchUser(admin, userHandle); |
| 5775 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5776 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5781 | * Retrieves the application restrictions for a given target application running in the calling |
| 5782 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5783 | * <p> |
| 5784 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5785 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5786 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5787 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5788 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5789 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5790 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5791 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5792 | * @param packageName The name of the package to fetch restricted settings of. |
| 5793 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5794 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 5795 | * {@link Bundle} if no restrictions have been set. |
| 5796 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5797 | * @see #setDelegatedScopes |
| 5798 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5799 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5800 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5801 | public @NonNull Bundle getApplicationRestrictions( |
| 5802 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5803 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5804 | if (mService != null) { |
| 5805 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5806 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 5807 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5808 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5809 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5810 | } |
| 5811 | } |
| 5812 | return null; |
| 5813 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5814 | |
| 5815 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5816 | * 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] | 5817 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5818 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5819 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5820 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5821 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5822 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5823 | * for the list of keys. |
| 5824 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5825 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5826 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5827 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5828 | if (mService != null) { |
| 5829 | try { |
| 5830 | mService.setUserRestriction(admin, key, true); |
| 5831 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5832 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5833 | } |
| 5834 | } |
| 5835 | } |
| 5836 | |
| 5837 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5838 | * 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] | 5839 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5840 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5841 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5842 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5843 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5844 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5845 | * for the list of keys. |
| 5846 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5847 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5848 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5849 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5850 | if (mService != null) { |
| 5851 | try { |
| 5852 | mService.setUserRestriction(admin, key, false); |
| 5853 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5854 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5855 | } |
| 5856 | } |
| 5857 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 5858 | |
| 5859 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5860 | * Called by a profile or device owner to get user restrictions set with |
| 5861 | * {@link #addUserRestriction(ComponentName, String)}. |
| 5862 | * <p> |
| 5863 | * 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] | 5864 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5865 | * {@link UserManager#getUserRestrictions()}. |
| 5866 | * |
| 5867 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5868 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5869 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5870 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5871 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5872 | Bundle ret = null; |
| 5873 | if (mService != null) { |
| 5874 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 5875 | ret = mService.getUserRestrictions(admin); |
| 5876 | } catch (RemoteException e) { |
| 5877 | throw e.rethrowFromSystemServer(); |
| 5878 | } |
| 5879 | } |
| 5880 | return ret == null ? new Bundle() : ret; |
| 5881 | } |
| 5882 | |
| 5883 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 5884 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 5885 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 5886 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 5887 | * was disabled by an admin, and include a link for more information. The default content of |
| 5888 | * the dialog can be changed by the restricting admin via |
| 5889 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 5890 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 5891 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 5892 | * user restriction from {@link UserManager}, e.g. |
| 5893 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
| 5894 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 5895 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 5896 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 5897 | */ |
| 5898 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 5899 | throwIfParentInstance("createAdminSupportIntent"); |
| 5900 | if (mService != null) { |
| 5901 | try { |
| 5902 | return mService.createAdminSupportIntent(restriction); |
| 5903 | } catch (RemoteException e) { |
| 5904 | throw e.rethrowFromSystemServer(); |
| 5905 | } |
| 5906 | } |
| 5907 | return null; |
| 5908 | } |
| 5909 | |
| 5910 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5911 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 5912 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 5913 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 5914 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5915 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5916 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5917 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5918 | * @param packageName The name of the package to hide or unhide. |
| 5919 | * @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] | 5920 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5921 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5922 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5923 | * @see #setDelegatedScopes |
| 5924 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5925 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5926 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5927 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5928 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5929 | if (mService != null) { |
| 5930 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5931 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 5932 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5933 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5934 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5935 | } |
| 5936 | } |
| 5937 | return false; |
| 5938 | } |
| 5939 | |
| 5940 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5941 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 5942 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 5943 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5944 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5945 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5946 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5947 | * @param packageName The name of the package to retrieve the hidden status of. |
| 5948 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5949 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5950 | * @see #setDelegatedScopes |
| 5951 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5952 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5953 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5954 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5955 | if (mService != null) { |
| 5956 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5957 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5958 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5959 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5960 | } |
| 5961 | } |
| 5962 | return false; |
| 5963 | } |
| 5964 | |
| 5965 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5966 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 5967 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 5968 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5969 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5970 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5971 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5972 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5973 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5974 | * @see #setDelegatedScopes |
| 5975 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5976 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5977 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5978 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5979 | if (mService != null) { |
| 5980 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5981 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5982 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5983 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5984 | } |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5989 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 5990 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 5991 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5992 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5993 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5994 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5995 | * @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] | 5996 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5997 | * @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] | 5998 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5999 | * @see #setDelegatedScopes |
| 6000 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6001 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6002 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6003 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6004 | if (mService != null) { |
| 6005 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6006 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6007 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6008 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6009 | } |
| 6010 | } |
| 6011 | return 0; |
| 6012 | } |
| 6013 | |
| 6014 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 6015 | * Called by a device owner or profile owner to disable account management for a specific type |
| 6016 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6017 | * <p> |
| 6018 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 6019 | * exception will be thrown. |
| 6020 | * <p> |
| 6021 | * When account management is disabled for an account type, adding or removing an account of |
| 6022 | * that type will not be possible. |
| 6023 | * <p> |
| 6024 | * 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] | 6025 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 6026 | * management for a specific type is disabled. |
| 6027 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6028 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6029 | * @param accountType For which account management is disabled or enabled. |
| 6030 | * @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] | 6031 | * enabled (false). |
| 6032 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6033 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6034 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6035 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6036 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6037 | if (mService != null) { |
| 6038 | try { |
| 6039 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 6040 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6041 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6042 | } |
| 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6047 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 6048 | * |
| 6049 | * <p> Account management can be disabled/enabled by calling |
| 6050 | * {@link #setAccountManagementDisabled}. |
| 6051 | * |
| 6052 | * @return a list of account types for which account management has been disabled. |
| 6053 | * |
| 6054 | * @see #setAccountManagementDisabled |
| 6055 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6056 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6057 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 6058 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6059 | } |
| 6060 | |
| 6061 | /** |
| 6062 | * @see #getAccountTypesWithManagementDisabled() |
| 6063 | * @hide |
| 6064 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6065 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6066 | if (mService != null) { |
| 6067 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6068 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6069 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6070 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6071 | } |
| 6072 | } |
| 6073 | |
| 6074 | return null; |
| 6075 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6076 | |
| 6077 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6078 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6079 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6080 | * Any packages that share uid with an allowed package will also be allowed to activate lock |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6081 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6082 | * package list results in locked tasks belonging to those packages to be finished. |
| 6083 | * <p> |
| 6084 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6085 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages |
| 6086 | * set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6087 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6088 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6089 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6090 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6091 | * an affiliated user or profile. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6092 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6093 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6094 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6095 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6096 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6097 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6098 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6099 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6100 | if (mService != null) { |
| 6101 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6102 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6103 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6104 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6105 | } |
| 6106 | } |
| 6107 | } |
| 6108 | |
| 6109 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6110 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6111 | * |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6112 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6113 | * an affiliated user or profile. |
| 6114 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6115 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6116 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6117 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6118 | if (mService != null) { |
| 6119 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6120 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6121 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6122 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6123 | } |
| 6124 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6125 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6126 | } |
| 6127 | |
| 6128 | /** |
| 6129 | * This function lets the caller know whether the given component is allowed to start the |
| 6130 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6131 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6132 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6133 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6134 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6135 | if (mService != null) { |
| 6136 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6137 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6138 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6139 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6140 | } |
| 6141 | } |
| 6142 | return false; |
| 6143 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6144 | |
| 6145 | /** |
| 6146 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 6147 | * 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] | 6148 | * <p> |
| 6149 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6150 | * <ul> |
| 6151 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 6152 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 6153 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6154 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6155 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6156 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6157 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 6158 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 6159 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 6160 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 6161 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6162 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6163 | * <p> |
| 6164 | * 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] | 6165 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6166 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 6167 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6168 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6169 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6170 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 6171 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6172 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6173 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 6174 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6175 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6176 | * |
| 6177 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6178 | * @param setting The name of the setting to update. |
| 6179 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6180 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6181 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6182 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6183 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6184 | if (mService != null) { |
| 6185 | try { |
| 6186 | mService.setGlobalSetting(admin, setting, value); |
| 6187 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6188 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6189 | } |
| 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | /** |
| 6194 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 6195 | * that the value of the setting is in the correct form for the setting type should be performed |
| 6196 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6197 | * <p> |
| 6198 | * 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] | 6199 | * <ul> |
| 6200 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 6201 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6202 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 6203 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6204 | * <p> |
| 6205 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6206 | * <ul> |
| 6207 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 6208 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6209 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6211 | * @param setting The name of the setting to update. |
| 6212 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6213 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6214 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6215 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6216 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6217 | if (mService != null) { |
| 6218 | try { |
| 6219 | mService.setSecureSetting(admin, setting, value); |
| 6220 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6221 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | } |
| 6225 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6226 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6227 | * Designates a specific service component as the provider for making permission requests of a |
| 6228 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6229 | * <p/> |
| 6230 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6231 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6232 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6233 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6234 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6235 | * provider previously assigned. |
| 6236 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6237 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6238 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6239 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6240 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6241 | if (mService != null) { |
| 6242 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6243 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6244 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6245 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6246 | } |
| 6247 | } |
| 6248 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6249 | |
| 6250 | /** |
| 6251 | * 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] | 6252 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6253 | * |
| 6254 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6255 | * @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] | 6256 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6257 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6258 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6259 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6260 | if (mService != null) { |
| 6261 | try { |
| 6262 | mService.setMasterVolumeMuted(admin, on); |
| 6263 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6264 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6265 | } |
| 6266 | } |
| 6267 | } |
| 6268 | |
| 6269 | /** |
| 6270 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6271 | * |
| 6272 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6273 | * @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] | 6274 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6275 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6276 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6277 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6278 | if (mService != null) { |
| 6279 | try { |
| 6280 | return mService.isMasterVolumeMuted(admin); |
| 6281 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6282 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6283 | } |
| 6284 | } |
| 6285 | return false; |
| 6286 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6287 | |
| 6288 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6289 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6290 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6291 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6292 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6293 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6294 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6295 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6296 | * @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] | 6297 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6298 | * @see #setDelegatedScopes |
| 6299 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6300 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6301 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6302 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6303 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6304 | if (mService != null) { |
| 6305 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6306 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6307 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6308 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6309 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6310 | } |
| 6311 | } |
| 6312 | } |
| 6313 | |
| 6314 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6315 | * 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] | 6316 | * 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] | 6317 | * <p> |
| 6318 | * <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] | 6319 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6320 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6321 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6322 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6323 | * @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] | 6324 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6325 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6326 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6327 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6328 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6329 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6330 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6331 | if (mService != null) { |
| 6332 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6333 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6334 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6335 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6336 | } |
| 6337 | } |
| 6338 | return false; |
| 6339 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6340 | |
| 6341 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6342 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6343 | * package to be available in the parent profile. As a result the user will be able to add |
| 6344 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6345 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6346 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6347 | * <p> |
| 6348 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6349 | * |
| 6350 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6351 | * @param packageName The package from which widget providers are white-listed. |
| 6352 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6353 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6354 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6355 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6356 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6357 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6358 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6359 | if (mService != null) { |
| 6360 | try { |
| 6361 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6362 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6363 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6364 | } |
| 6365 | } |
| 6366 | return false; |
| 6367 | } |
| 6368 | |
| 6369 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6370 | * 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] | 6371 | * package to be available in the parent profile. For this method to take effect the package |
| 6372 | * should have been added via |
| 6373 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6374 | * <p> |
| 6375 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6376 | * |
| 6377 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6378 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6379 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6380 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6381 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6382 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6383 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6384 | public boolean removeCrossProfileWidgetProvider( |
| 6385 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6386 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6387 | if (mService != null) { |
| 6388 | try { |
| 6389 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6390 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6391 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6392 | } |
| 6393 | } |
| 6394 | return false; |
| 6395 | } |
| 6396 | |
| 6397 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6398 | * 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] | 6399 | * available in the parent profile. |
| 6400 | * |
| 6401 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6402 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6403 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6404 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6405 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6406 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6407 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6408 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6409 | if (mService != null) { |
| 6410 | try { |
| 6411 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6412 | if (providers != null) { |
| 6413 | return providers; |
| 6414 | } |
| 6415 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6416 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6417 | } |
| 6418 | } |
| 6419 | return Collections.emptyList(); |
| 6420 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6421 | |
| 6422 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6423 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6424 | * |
| 6425 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6426 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6427 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6429 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6430 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6431 | try { |
| 6432 | mService.setUserIcon(admin, icon); |
| 6433 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6434 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6435 | } |
| 6436 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6437 | |
| 6438 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6439 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6440 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6441 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6442 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6443 | * components in the device owner package can set system update policies and the most |
| 6444 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6445 | * @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] | 6446 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6447 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6448 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6449 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6450 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6451 | if (mService != null) { |
| 6452 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6453 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6454 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6455 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6456 | } |
| 6457 | } |
| 6458 | } |
| 6459 | |
| 6460 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6461 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6462 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6463 | * @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] | 6464 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6465 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6466 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6467 | if (mService != null) { |
| 6468 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6469 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6470 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6471 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6472 | } |
| 6473 | } |
| 6474 | return null; |
| 6475 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6476 | |
| 6477 | /** |
| 6478 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6479 | * <p> |
| 6480 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6481 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6482 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6483 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6484 | * |
| 6485 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6486 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6487 | * @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] | 6488 | * place. {@code true} otherwise. |
| 6489 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6490 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6491 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6492 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6493 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6494 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6495 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6496 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6497 | } |
| 6498 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6499 | |
| 6500 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6501 | * 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] | 6502 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6503 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6504 | * |
| 6505 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6506 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6507 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6508 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6509 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6510 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6511 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6512 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6513 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6514 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6515 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6516 | } |
| 6517 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6518 | |
| 6519 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6520 | * Called by the system update service to notify device and profile owners of pending system |
| 6521 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6522 | * |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6523 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6524 | * permission. This method should only be used when it is unknown whether the pending system |
| 6525 | * update is a security patch. Otherwise, use |
| 6526 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 6527 | * |
| 6528 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6529 | * indicating when the current pending update was first available. {@code -1} if no |
| 6530 | * update is available. |
| 6531 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6532 | * @hide |
| 6533 | */ |
| 6534 | @SystemApi |
| 6535 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6536 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6537 | if (mService != null) { |
| 6538 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6539 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 6540 | } catch (RemoteException re) { |
| 6541 | throw re.rethrowFromSystemServer(); |
| 6542 | } |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | /** |
| 6547 | * Called by the system update service to notify device and profile owners of pending system |
| 6548 | * updates. |
| 6549 | * |
| 6550 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6551 | * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
| 6552 | * when it is known whether the pending system update is a security patch. |
| 6553 | * |
| 6554 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6555 | * indicating when the current pending update was first available. {@code -1} if no |
| 6556 | * update is available. |
| 6557 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 6558 | * {@code false} if not. |
| 6559 | * @see #notifyPendingSystemUpdate(long) |
| 6560 | * @hide |
| 6561 | */ |
| 6562 | @SystemApi |
| 6563 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 6564 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 6565 | if (mService != null) { |
| 6566 | try { |
| 6567 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 6568 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6569 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6570 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6571 | } |
| 6572 | } |
| 6573 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6574 | |
| 6575 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 6576 | * Called by device or profile owners to get information about a pending system update. |
| 6577 | * |
| 6578 | * @param admin Which profile or device owner this request is associated with. |
| 6579 | * @return Information about a pending system update or {@code null} if no update pending. |
| 6580 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 6581 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 6582 | */ |
| 6583 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 6584 | throwIfParentInstance("getPendingSystemUpdate"); |
| 6585 | try { |
| 6586 | return mService.getPendingSystemUpdate(admin); |
| 6587 | } catch (RemoteException re) { |
| 6588 | throw re.rethrowFromSystemServer(); |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6593 | * Set the default response for future runtime permission requests by applications. This |
| 6594 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6595 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 6596 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 6597 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 6598 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 6599 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 6600 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6601 | * <p/> |
| 6602 | * 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] | 6603 | * 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] | 6604 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6605 | * @param admin Which profile or device owner this request is associated with. |
| 6606 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6607 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6608 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6609 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6610 | * @see #setDelegatedScopes |
| 6611 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6612 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6613 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6614 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6615 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6616 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6617 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6618 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | /** |
| 6623 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6624 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6625 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6626 | * @param admin Which profile or device owner this request is associated with. |
| 6627 | * @return the current policy for future permission requests. |
| 6628 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6629 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6630 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6631 | try { |
| 6632 | return mService.getPermissionPolicy(admin); |
| 6633 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6634 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6639 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6640 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6641 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6642 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6643 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6644 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6645 | * by a profile owner, device owner, or a delegate given the |
| 6646 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6647 | * <p/> |
| 6648 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6649 | * the permission. It retains the previous grant, if any. |
| 6650 | * <p/> |
| 6651 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6652 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6653 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6654 | * @param admin Which profile or device owner this request is associated with. |
| 6655 | * @param packageName The application to grant or revoke a permission to. |
| 6656 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6657 | * @param grantState The permission grant state which is one of |
| 6658 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6659 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6660 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6661 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6662 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6663 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6664 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6665 | * @see #setDelegatedScopes |
| 6666 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6667 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6668 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6669 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6670 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6671 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6672 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6673 | permission, grantState); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6674 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6675 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6676 | } |
| 6677 | } |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6678 | |
| 6679 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6680 | * Returns the current grant state of a runtime permission for a specific application. This |
| 6681 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6682 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6683 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6684 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 6685 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6686 | * @param packageName The application to check the grant state for. |
| 6687 | * @param permission The permission to check for. |
| 6688 | * @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] | 6689 | * has not set a grant state, the return value is |
| 6690 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6691 | * permission is currently granted for the package. |
| 6692 | * <p/> |
| 6693 | * If a grant state was set by the profile or device owner, then the return value will |
| 6694 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6695 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6696 | * currently denied or granted. |
| 6697 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6698 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6699 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6700 | * @see #setDelegatedScopes |
| 6701 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6702 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 6703 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6704 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6705 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6706 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6707 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6708 | permission); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6709 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6710 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6711 | } |
| 6712 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6713 | |
| 6714 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6715 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 6716 | * or device, setting itself as the device or profile owner. |
| 6717 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6718 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6719 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6720 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6721 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 6722 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6723 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6724 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6725 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6726 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6727 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6728 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6729 | } |
| 6730 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6731 | |
| 6732 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6733 | * Checks whether it is possible to initiate provisioning a managed device, |
| 6734 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6735 | * |
| 6736 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6737 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 6738 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 6739 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6740 | * @param packageName The package of the component that would be set as device, user, or profile |
| 6741 | * owner. |
| 6742 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6743 | * @hide |
| 6744 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6745 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 6746 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6747 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6748 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6749 | } catch (RemoteException re) { |
| 6750 | throw re.rethrowFromSystemServer(); |
| 6751 | } |
| 6752 | } |
| 6753 | |
| 6754 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6755 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 6756 | * 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] | 6757 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6758 | * @param admin Which profile owner this request is associated with. |
| 6759 | * @return if this user is a managed profile of another user. |
| 6760 | */ |
| 6761 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6762 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6763 | try { |
| 6764 | return mService.isManagedProfile(admin); |
| 6765 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6766 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6767 | } |
| 6768 | } |
| 6769 | |
| 6770 | /** |
| 6771 | * @hide |
| 6772 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 6773 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 6774 | * @param admin Which device owner this request is associated with. |
| 6775 | * @return if this user is a system-only user. |
| 6776 | */ |
| 6777 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 6778 | try { |
| 6779 | return mService.isSystemOnlyUser(admin); |
| 6780 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6781 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6782 | } |
| 6783 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6784 | |
| 6785 | /** |
| 6786 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 6787 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6788 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6789 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 6790 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 6791 | * <p> |
| 6792 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 6793 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6794 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6795 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6796 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6797 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6798 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6799 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6800 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6801 | } |
| 6802 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6803 | |
| 6804 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6805 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 6806 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6807 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6808 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6809 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6810 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6811 | */ |
| 6812 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6813 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6814 | try { |
| 6815 | mService.reboot(admin); |
| 6816 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6817 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6818 | } |
| 6819 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6820 | |
| 6821 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6822 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 6823 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 6824 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 6825 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 6826 | * truncated. |
| 6827 | * <p> |
| 6828 | * 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] | 6829 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6830 | * and set a new version of this string accordingly. |
| 6831 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6832 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6833 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6834 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 6835 | * existing message. |
| 6836 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6837 | */ |
| 6838 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6839 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6840 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6841 | if (mService != null) { |
| 6842 | try { |
| 6843 | mService.setShortSupportMessage(admin, message); |
| 6844 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6845 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6846 | } |
| 6847 | } |
| 6848 | } |
| 6849 | |
| 6850 | /** |
| 6851 | * Called by a device admin to get the short support message. |
| 6852 | * |
| 6853 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6854 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 6855 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6856 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6857 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6858 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6859 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6860 | if (mService != null) { |
| 6861 | try { |
| 6862 | return mService.getShortSupportMessage(admin); |
| 6863 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6864 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6865 | } |
| 6866 | } |
| 6867 | return null; |
| 6868 | } |
| 6869 | |
| 6870 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6871 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 6872 | * in the device administators settings screen. |
| 6873 | * <p> |
| 6874 | * 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] | 6875 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6876 | * and set a new version of this string accordingly. |
| 6877 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6878 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6879 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6880 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 6881 | * existing message. |
| 6882 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6883 | */ |
| 6884 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6885 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6886 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6887 | if (mService != null) { |
| 6888 | try { |
| 6889 | mService.setLongSupportMessage(admin, message); |
| 6890 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6891 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6892 | } |
| 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | /** |
| 6897 | * Called by a device admin to get the long support message. |
| 6898 | * |
| 6899 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6900 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 6901 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6902 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6903 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6904 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6905 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6906 | if (mService != null) { |
| 6907 | try { |
| 6908 | return mService.getLongSupportMessage(admin); |
| 6909 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6910 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6911 | } |
| 6912 | } |
| 6913 | return null; |
| 6914 | } |
| 6915 | |
| 6916 | /** |
| 6917 | * Called by the system to get the short support message. |
| 6918 | * |
| 6919 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6920 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6921 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6922 | * |
| 6923 | * @hide |
| 6924 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6925 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6926 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6927 | if (mService != null) { |
| 6928 | try { |
| 6929 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 6930 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6931 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6932 | } |
| 6933 | } |
| 6934 | return null; |
| 6935 | } |
| 6936 | |
| 6937 | |
| 6938 | /** |
| 6939 | * Called by the system to get the long support message. |
| 6940 | * |
| 6941 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6942 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6943 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6944 | * |
| 6945 | * @hide |
| 6946 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6947 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 6948 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6949 | if (mService != null) { |
| 6950 | try { |
| 6951 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 6952 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6953 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6954 | } |
| 6955 | } |
| 6956 | return null; |
| 6957 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6958 | |
| 6959 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6960 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 6961 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6962 | * |
| 6963 | * <p>The following methods are supported for the parent instance, all other methods will |
| 6964 | * throw a SecurityException when called on the parent instance: |
| 6965 | * <ul> |
| 6966 | * <li>{@link #getPasswordQuality}</li> |
| 6967 | * <li>{@link #setPasswordQuality}</li> |
| 6968 | * <li>{@link #getPasswordMinimumLength}</li> |
| 6969 | * <li>{@link #setPasswordMinimumLength}</li> |
| 6970 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 6971 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 6972 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 6973 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 6974 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 6975 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 6976 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 6977 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 6978 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 6979 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 6980 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 6981 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 6982 | * <li>{@link #getPasswordHistoryLength}</li> |
| 6983 | * <li>{@link #setPasswordHistoryLength}</li> |
| 6984 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 6985 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 6986 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 6987 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6988 | * <li>{@link #isActivePasswordSufficient}</li> |
| 6989 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 6990 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 6991 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 6992 | * <li>{@link #getMaximumTimeToLock}</li> |
| 6993 | * <li>{@link #setMaximumTimeToLock}</li> |
| 6994 | * <li>{@link #lockNow}</li> |
| 6995 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 6996 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 6997 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 6998 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 6999 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 7000 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7001 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7002 | * |
| 7003 | * @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] | 7004 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7005 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7006 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7007 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7008 | try { |
| 7009 | if (!mService.isManagedProfile(admin)) { |
| 7010 | throw new SecurityException("The current user does not have a parent profile."); |
| 7011 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7012 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7013 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7014 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7015 | } |
| 7016 | } |
| 7017 | |
| 7018 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7019 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7020 | * |
| 7021 | * <p> Security logs contain various information intended for security auditing purposes. |
| 7022 | * See {@link SecurityEvent} for details. |
| 7023 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7024 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 7025 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7026 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7027 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7028 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7029 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7030 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7031 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7032 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7033 | * @see #retrieveSecurityLogs |
| 7034 | */ |
| 7035 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7036 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7037 | try { |
| 7038 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 7039 | } catch (RemoteException re) { |
| 7040 | throw re.rethrowFromSystemServer(); |
| 7041 | } |
| 7042 | } |
| 7043 | |
| 7044 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7045 | * Return whether security logging is enabled or not by the device owner. |
| 7046 | * |
| 7047 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 7048 | * thrown. |
| 7049 | * |
| 7050 | * @param admin Which device owner this request is associated with. |
| 7051 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 7052 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7053 | */ |
| 7054 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7055 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7056 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7057 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7058 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7059 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7060 | } |
| 7061 | } |
| 7062 | |
| 7063 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7064 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 7065 | * this API after device boots. |
| 7066 | * |
| 7067 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 7068 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 7069 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7070 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7071 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7072 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7073 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7074 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7075 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 7076 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7077 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7078 | * profile or secondary user that is not affiliated with the device owner user. |
| 7079 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7080 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7081 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7082 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7083 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7084 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7085 | if (list != null) { |
| 7086 | return list.getList(); |
| 7087 | } else { |
| 7088 | // Rate limit exceeded. |
| 7089 | return null; |
| 7090 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7091 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7092 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7093 | } |
| 7094 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7095 | |
| 7096 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7097 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7098 | * profile. |
| 7099 | * |
| 7100 | * @hide |
| 7101 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7102 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7103 | mContext.checkSelfPermission( |
| 7104 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7105 | if (!uInfo.isManagedProfile()) { |
| 7106 | throw new SecurityException("The user " + uInfo.id |
| 7107 | + " does not have a parent profile."); |
| 7108 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7109 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7110 | } |
| 7111 | |
| 7112 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7113 | * 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] | 7114 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7115 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7116 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7117 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7118 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7119 | * |
| 7120 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7121 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7122 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7123 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7124 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7125 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7126 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7127 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7128 | * profile or secondary user that is not affiliated with the device owner user. |
| 7129 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7130 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7131 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7132 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7133 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7134 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7135 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7136 | if (list != null) { |
| 7137 | return list.getList(); |
| 7138 | } else { |
| 7139 | return null; |
| 7140 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7141 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7142 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7143 | } |
| 7144 | } |
| 7145 | |
| 7146 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7147 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7148 | * 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] | 7149 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7150 | * <p> |
| 7151 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7152 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7153 | * |
| 7154 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7155 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7156 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7157 | */ |
| 7158 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7159 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7160 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7161 | // always enforce alpha channel to have 100% opacity |
| 7162 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7163 | mService.setOrganizationColor(admin, color); |
| 7164 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7165 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7166 | } |
| 7167 | } |
| 7168 | |
| 7169 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7170 | * @hide |
| 7171 | * |
| 7172 | * Sets the color used for customization. |
| 7173 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7174 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7175 | * @param userId which user to set the color to. |
| 7176 | * @RequiresPermission(allOf = { |
| 7177 | * Manifest.permission.MANAGE_USERS, |
| 7178 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7179 | */ |
| 7180 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7181 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7182 | // always enforce alpha channel to have 100% opacity |
| 7183 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7184 | mService.setOrganizationColorForUser(color, userId); |
| 7185 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7186 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7187 | } |
| 7188 | } |
| 7189 | |
| 7190 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7191 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7192 | * This color is used as background color of the confirm credentials screen for that user. |
| 7193 | * |
| 7194 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7195 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7196 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7197 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7198 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7199 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7200 | try { |
| 7201 | return mService.getOrganizationColor(admin); |
| 7202 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7203 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7204 | } |
| 7205 | } |
| 7206 | |
| 7207 | /** |
| 7208 | * @hide |
| 7209 | * Retrieve the customization color for a given user. |
| 7210 | * |
| 7211 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7212 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7213 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7214 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7215 | try { |
| 7216 | return mService.getOrganizationColorForUser(userHandle); |
| 7217 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7218 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7219 | } |
| 7220 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7221 | |
| 7222 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7223 | * 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] | 7224 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7225 | * <p> |
| 7226 | * 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] | 7227 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7228 | * and set a new version of this string accordingly. |
| 7229 | * |
| 7230 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7231 | * @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] | 7232 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7233 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7234 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7235 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7236 | try { |
| 7237 | mService.setOrganizationName(admin, title); |
| 7238 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7239 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7244 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7245 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7246 | * |
| 7247 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7248 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7249 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7250 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7251 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7252 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7253 | try { |
| 7254 | return mService.getOrganizationName(admin); |
| 7255 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7256 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7257 | } |
| 7258 | } |
| 7259 | |
| 7260 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7261 | * Called by the system to retrieve the name of the organization managing the device. |
| 7262 | * |
| 7263 | * @return The organization name or {@code null} if none is set. |
| 7264 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7265 | * MANAGE_USERS permission and is not the system. |
| 7266 | * |
| 7267 | * @hide |
| 7268 | */ |
| 7269 | @SystemApi |
| 7270 | @TestApi |
| 7271 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7272 | try { |
| 7273 | return mService.getDeviceOwnerOrganizationName(); |
| 7274 | } catch (RemoteException re) { |
| 7275 | throw re.rethrowFromSystemServer(); |
| 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7280 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7281 | * |
| 7282 | * @param userHandle The user id of the user we're interested in. |
| 7283 | * @return The organization name or {@code null} if none is set. |
| 7284 | * |
| 7285 | * @hide |
| 7286 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7287 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7288 | try { |
| 7289 | return mService.getOrganizationNameForUser(userHandle); |
| 7290 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7291 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7296 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7297 | * return {@link #STATE_USER_UNMANAGED} |
| 7298 | * @hide |
| 7299 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7300 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7301 | @UserProvisioningState |
| 7302 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7303 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7304 | if (mService != null) { |
| 7305 | try { |
| 7306 | return mService.getUserProvisioningState(); |
| 7307 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7308 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7309 | } |
| 7310 | } |
| 7311 | return STATE_USER_UNMANAGED; |
| 7312 | } |
| 7313 | |
| 7314 | /** |
| 7315 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7316 | * |
| 7317 | * @param state to store |
| 7318 | * @param userHandle for user |
| 7319 | * @hide |
| 7320 | */ |
| 7321 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7322 | if (mService != null) { |
| 7323 | try { |
| 7324 | mService.setUserProvisioningState(state, userHandle); |
| 7325 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7326 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7327 | } |
| 7328 | } |
| 7329 | } |
| 7330 | |
| 7331 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7332 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7333 | * 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] | 7334 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7335 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7336 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7337 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7338 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7339 | * created. |
| 7340 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7341 | * @param admin Which profile or device owner this request is associated with. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7342 | * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored. |
| 7343 | * |
| 7344 | * @throws NullPointerException if {@code ids} is null or contains null elements. |
| 7345 | * @throws IllegalArgumentException if {@code ids} contains an empty string. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7346 | */ |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7347 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7348 | throwIfParentInstance("setAffiliationIds"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7349 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7350 | mService.setAffiliationIds(admin, ids); |
| 7351 | } catch (RemoteException e) { |
| 7352 | throw e.rethrowFromSystemServer(); |
| 7353 | } |
| 7354 | } |
| 7355 | |
| 7356 | /** |
| 7357 | * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7358 | * empty list if none have been set. |
| 7359 | */ |
| 7360 | public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) { |
| 7361 | throwIfParentInstance("getAffiliationIds"); |
| 7362 | try { |
| 7363 | return mService.getAffiliationIds(admin); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7364 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7365 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7366 | } |
| 7367 | } |
| 7368 | |
| 7369 | /** |
| 7370 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7371 | * Returns whether this user/profile is affiliated with the device. |
| 7372 | * <p> |
| 7373 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7374 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7375 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7376 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7377 | */ |
| 7378 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7379 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7380 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7381 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7382 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7383 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7384 | } |
| 7385 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7386 | |
| 7387 | /** |
| 7388 | * @hide |
| 7389 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7390 | * to be started |
| 7391 | * @param packageName the package to check for |
| 7392 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7393 | */ |
| 7394 | public boolean isUninstallInQueue(String packageName) { |
| 7395 | try { |
| 7396 | return mService.isUninstallInQueue(packageName); |
| 7397 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7398 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | /** |
| 7403 | * @hide |
| 7404 | * @param packageName the package containing active DAs to be uninstalled |
| 7405 | */ |
| 7406 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7407 | try { |
| 7408 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7409 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7410 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7411 | } |
| 7412 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7413 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7414 | /** |
| 7415 | * @hide |
| 7416 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7417 | * If the admin is a profile owner or device owner it will still be removed. |
| 7418 | * |
| 7419 | * @param userHandle user id to remove the admin for. |
| 7420 | * @param admin The administration compononent to remove. |
| 7421 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7422 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7423 | */ |
| 7424 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7425 | try { |
| 7426 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7427 | } catch (RemoteException re) { |
| 7428 | throw re.rethrowFromSystemServer(); |
| 7429 | } |
| 7430 | } |
| 7431 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7432 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7433 | * Returns whether the device has been provisioned. |
| 7434 | * |
| 7435 | * <p>Not for use by third-party applications. |
| 7436 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7437 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7438 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7439 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7440 | public boolean isDeviceProvisioned() { |
| 7441 | try { |
| 7442 | return mService.isDeviceProvisioned(); |
| 7443 | } catch (RemoteException re) { |
| 7444 | throw re.rethrowFromSystemServer(); |
| 7445 | } |
| 7446 | } |
| 7447 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7448 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7449 | * Writes that the provisioning configuration has been applied. |
| 7450 | * |
| 7451 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7452 | * permission. |
| 7453 | * |
| 7454 | * <p>Not for use by third-party applications. |
| 7455 | * |
| 7456 | * @hide |
| 7457 | */ |
| 7458 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7459 | public void setDeviceProvisioningConfigApplied() { |
| 7460 | try { |
| 7461 | mService.setDeviceProvisioningConfigApplied(); |
| 7462 | } catch (RemoteException re) { |
| 7463 | throw re.rethrowFromSystemServer(); |
| 7464 | } |
| 7465 | } |
| 7466 | |
| 7467 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7468 | * Returns whether the provisioning configuration has been applied. |
| 7469 | * |
| 7470 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7471 | * |
| 7472 | * <p>Not for use by third-party applications. |
| 7473 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7474 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7475 | * |
| 7476 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7477 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7478 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7479 | public boolean isDeviceProvisioningConfigApplied() { |
| 7480 | try { |
| 7481 | return mService.isDeviceProvisioningConfigApplied(); |
| 7482 | } catch (RemoteException re) { |
| 7483 | throw re.rethrowFromSystemServer(); |
| 7484 | } |
| 7485 | } |
| 7486 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7487 | /** |
| 7488 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7489 | * Force update user setup completed status. This API has no effect on user build. |
| 7490 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7491 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7492 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7493 | */ |
| 7494 | public void forceUpdateUserSetupComplete() { |
| 7495 | try { |
| 7496 | mService.forceUpdateUserSetupComplete(); |
| 7497 | } catch (RemoteException re) { |
| 7498 | throw re.rethrowFromSystemServer(); |
| 7499 | } |
| 7500 | } |
| 7501 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7502 | private void throwIfParentInstance(String functionName) { |
| 7503 | if (mParentInstance) { |
| 7504 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7505 | } |
| 7506 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7507 | |
| 7508 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7509 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7510 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7511 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 7512 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7513 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7514 | * <p> Backup service is off by default when device owner is present. |
| 7515 | * |
| 7516 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7517 | */ |
| 7518 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7519 | try { |
| 7520 | mService.setBackupServiceEnabled(admin, enabled); |
| 7521 | } catch (RemoteException re) { |
| 7522 | throw re.rethrowFromSystemServer(); |
| 7523 | } |
| 7524 | } |
| 7525 | |
| 7526 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7527 | * Return whether the backup service is enabled by the device owner. |
| 7528 | * |
| 7529 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 7530 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7531 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7532 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7533 | */ |
| 7534 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
| 7535 | try { |
| 7536 | return mService.isBackupServiceEnabled(admin); |
| 7537 | } catch (RemoteException re) { |
| 7538 | throw re.rethrowFromSystemServer(); |
| 7539 | } |
| 7540 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7541 | |
| 7542 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7543 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7544 | * |
| 7545 | * <p> Network logs contain DNS lookup and connect() library call events. |
| 7546 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7547 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7548 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7549 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7550 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7551 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7552 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7553 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7554 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7555 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7556 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7557 | */ |
| 7558 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7559 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7560 | try { |
| 7561 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7562 | } catch (RemoteException re) { |
| 7563 | throw re.rethrowFromSystemServer(); |
| 7564 | } |
| 7565 | } |
| 7566 | |
| 7567 | /** |
| 7568 | * Return whether network logging is enabled by a device owner. |
| 7569 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7570 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7571 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7572 | * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7573 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7574 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7575 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7576 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7577 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7578 | try { |
| 7579 | return mService.isNetworkLoggingEnabled(admin); |
| 7580 | } catch (RemoteException re) { |
| 7581 | throw re.rethrowFromSystemServer(); |
| 7582 | } |
| 7583 | } |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7584 | |
| 7585 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7586 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7587 | * A device owner has to provide a batchToken provided as part of |
| 7588 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7589 | * token of the most recent available batch of logs, {@code null} will be returned. |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7590 | * |
| 7591 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7592 | * |
| 7593 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7594 | * |
| 7595 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7596 | * after the device device owner has been notified via |
| 7597 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7598 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7599 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7600 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7601 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7602 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7603 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7604 | * |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7605 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7606 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7607 | * @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] | 7608 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7609 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7610 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7611 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7612 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7613 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7614 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7615 | long batchToken) { |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7616 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7617 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7618 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7619 | } catch (RemoteException re) { |
| 7620 | throw re.rethrowFromSystemServer(); |
| 7621 | } |
| 7622 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7623 | |
| 7624 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7625 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 7626 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7627 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7628 | * <p> |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7629 | * The service must be unexported. Note that the {@link Context} used to obtain this |
| 7630 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7631 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7632 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7633 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7634 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7635 | * explicit component name or a package name to match an |
| 7636 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7637 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7638 | * must be a valid {@link ServiceConnection} object; it must not be {@code null}. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7639 | * @param flags Operation options for the binding operation. See |
| 7640 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7641 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7642 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7643 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7644 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7645 | * {@code false} is returned if the connection is not made and you will not |
| 7646 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7647 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7648 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7649 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7650 | */ |
| 7651 | public boolean bindDeviceAdminServiceAsUser( |
| 7652 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7653 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7654 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7655 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7656 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7657 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 7658 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7659 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7660 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7661 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7662 | sd, flags, targetUser.getIdentifier()); |
| 7663 | } catch (RemoteException re) { |
| 7664 | throw re.rethrowFromSystemServer(); |
| 7665 | } |
| 7666 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7667 | |
| 7668 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7669 | * Returns the list of target users that the calling device or profile owner can use when |
| 7670 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 7671 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7672 | * A device owner can bind to a service from a profile owner and vice versa, provided that: |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7673 | * <ul> |
| 7674 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7675 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7676 | * </ul> |
| 7677 | */ |
| 7678 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 7679 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 7680 | try { |
| 7681 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 7682 | } catch (RemoteException re) { |
| 7683 | throw re.rethrowFromSystemServer(); |
| 7684 | } |
| 7685 | } |
| 7686 | |
| 7687 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7688 | * Called by the system to get the time at which the device owner last retrieved security |
| 7689 | * logging entries. |
| 7690 | * |
| 7691 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 7692 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7693 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7694 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7695 | * |
| 7696 | * @hide |
| 7697 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7698 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7699 | public long getLastSecurityLogRetrievalTime() { |
| 7700 | try { |
| 7701 | return mService.getLastSecurityLogRetrievalTime(); |
| 7702 | } catch (RemoteException re) { |
| 7703 | throw re.rethrowFromSystemServer(); |
| 7704 | } |
| 7705 | } |
| 7706 | |
| 7707 | /** |
| 7708 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 7709 | * |
| 7710 | * @return the time at which the device owner most recently requested a bug report, in |
| 7711 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7712 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7713 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7714 | * |
| 7715 | * @hide |
| 7716 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7717 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7718 | public long getLastBugReportRequestTime() { |
| 7719 | try { |
| 7720 | return mService.getLastBugReportRequestTime(); |
| 7721 | } catch (RemoteException re) { |
| 7722 | throw re.rethrowFromSystemServer(); |
| 7723 | } |
| 7724 | } |
| 7725 | |
| 7726 | /** |
| 7727 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 7728 | * events. |
| 7729 | * |
| 7730 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 7731 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7732 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7733 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7734 | * |
| 7735 | * @hide |
| 7736 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7737 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7738 | public long getLastNetworkLogRetrievalTime() { |
| 7739 | try { |
| 7740 | return mService.getLastNetworkLogRetrievalTime(); |
| 7741 | } catch (RemoteException re) { |
| 7742 | throw re.rethrowFromSystemServer(); |
| 7743 | } |
| 7744 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 7745 | } |