Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
| 25 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 26 | import android.annotation.SystemApi; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 27 | import android.annotation.TestApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 28 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 29 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 30 | import android.app.Activity; |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 31 | import android.app.admin.PasswordMetrics; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 32 | import android.app.IServiceConnection; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 33 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 34 | import android.content.ComponentName; |
| 35 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 36 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 37 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 38 | import android.content.ServiceConnection; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 40 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 41 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 42 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 43 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 44 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 45 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 46 | import android.os.Bundle; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 47 | import android.os.Parcelable; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 49 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 50 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 52 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 53 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 54 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 55 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 56 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 57 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 58 | import android.telephony.TelephonyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 59 | import android.util.Log; |
| 60 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 61 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 62 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 63 | |
| 64 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 65 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 66 | import java.lang.annotation.Retention; |
| 67 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 68 | import java.net.InetSocketAddress; |
| 69 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 70 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 71 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 72 | import java.security.PrivateKey; |
| 73 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 74 | import java.security.cert.CertificateException; |
| 75 | import java.security.cert.CertificateFactory; |
| 76 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 77 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 78 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 79 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 80 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 81 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 82 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 85 | * 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] | 86 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 87 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 88 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 89 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 90 | * application calling an api may only pass as an argument a device administrator component it |
| 91 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 92 | * <div class="special reference"> |
| 93 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 94 | * <p> |
| 95 | * For more information about managing policies for device administration, read the <a href= |
| 96 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 97 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | */ |
| 99 | public class DevicePolicyManager { |
| 100 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 101 | |
| 102 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 103 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 104 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 105 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 106 | /** @hide */ |
| 107 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 108 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 111 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 112 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 113 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 114 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 115 | mContext = context; |
| 116 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 117 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | /** @hide test will override it. */ |
| 121 | @VisibleForTesting |
| 122 | protected int myUserId() { |
| 123 | return UserHandle.myUserId(); |
| 124 | } |
| 125 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 126 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 127 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 128 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 129 | * <p>A managed profile allows data separation for example for the usage of a |
| 130 | * device as a personal and corporate device. The user which provisioning is started from and |
| 131 | * the managed profile share a launcher. |
| 132 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 133 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 134 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 135 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 136 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 137 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 138 | * {@link #isProvisioningAllowed(String)}. |
| 139 | * |
| 140 | * <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] | 141 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 142 | * 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] | 143 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 144 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 145 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 146 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 147 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 148 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 149 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 150 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 152 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 153 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 154 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 155 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 156 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 157 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 158 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 159 | * <p>When managed provisioning has completed, broadcasts are sent to the application specified |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 160 | * in the provisioning intent. The |
| 161 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 162 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 163 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 164 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 165 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 166 | * completed, along with the above broadcast, activity intent |
| 167 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in |
| 168 | * the provisioning intent. |
| 169 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 170 | * <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] | 171 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 172 | * |
| 173 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 174 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 175 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 176 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 177 | * 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] | 178 | */ |
| 179 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 180 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 181 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 182 | |
| 183 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 184 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 185 | * |
| 186 | * <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] | 187 | * 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] | 188 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 189 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 190 | * allowed. |
| 191 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 192 | * <p>The intent contains the following extras: |
| 193 | * <ul> |
| 194 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 195 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 196 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 197 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 198 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 199 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 200 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 201 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 202 | * |
| 203 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 204 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 205 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 206 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 207 | * 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] | 208 | * |
| 209 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 210 | */ |
| 211 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 212 | public static final String ACTION_PROVISION_MANAGED_USER |
| 213 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 214 | |
| 215 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 216 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 217 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 218 | * |
| 219 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 220 | * A device owner has full control over the device. The device owner can not be modified by the |
| 221 | * user. |
| 222 | * |
| 223 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 224 | * employee or client. |
| 225 | * |
| 226 | * <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] | 227 | * It is possible to check if provisioning is allowed or not by querying the method |
| 228 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 229 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 230 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 231 | * <ul> |
| 232 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 233 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 234 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 235 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 236 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 237 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 238 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 239 | * </ul> |
| 240 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 241 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 242 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 243 | * device owner. |
| 244 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 245 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 246 | * completed, along with the above broadcast, activity intent |
| 247 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 248 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 249 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 250 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 251 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 252 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 253 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 254 | * 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] | 255 | */ |
| 256 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 257 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 258 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 259 | |
| 260 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 261 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 262 | * |
| 263 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 264 | * the device. A device owner has full control over the device. The device owner can not be |
| 265 | * modified by the user and the only way of resetting the device is via factory reset. |
| 266 | * |
| 267 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 268 | * employee or client. |
| 269 | * |
| 270 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 271 | * |
| 272 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 273 | * by a privileged app with the permission |
| 274 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 275 | * |
| 276 | * <p>The provisioning intent contains the following properties: |
| 277 | * <ul> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 279 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 280 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 281 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 282 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 283 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 284 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 285 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 286 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 287 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 288 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 289 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 290 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 291 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 292 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 293 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 294 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 295 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 296 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 297 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 298 | * |
| 299 | * @hide |
| 300 | */ |
| 301 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 302 | @SystemApi |
| 303 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 304 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 305 | |
| 306 | /** |
| 307 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 308 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 309 | * |
| 310 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 311 | * management state that is distinct from that reached by |
| 312 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 313 | * user, and only has control over device-wide policies, not individual users and their data. |
| 314 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 315 | * this form of device management. |
| 316 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 317 | * <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] | 318 | * A device owner has full control over the device. The device owner can not be modified by the |
| 319 | * user. |
| 320 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 321 | * <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] | 322 | * employee or client. |
| 323 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 324 | * <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] | 325 | * It is possible to check if provisioning is allowed or not by querying the method |
| 326 | * {@link #isProvisioningAllowed(String)}. |
| 327 | * |
| 328 | * <p>The intent contains the following extras: |
| 329 | * <ul> |
| 330 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 331 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 332 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 333 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 334 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 335 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 336 | * </ul> |
| 337 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 338 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 339 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 340 | * device owner. |
| 341 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 342 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 343 | * completed, along with the above broadcast, activity intent |
| 344 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 345 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 346 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 347 | * |
| 348 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 349 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 350 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 351 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 352 | * |
| 353 | * @hide |
| 354 | */ |
| 355 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 356 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 357 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 358 | |
| 359 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 360 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 361 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 362 | * <ul> |
| 363 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 364 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 365 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 366 | * </ul> |
| 367 | * |
| 368 | * @hide |
| 369 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 370 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 371 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 372 | public static final String ACTION_PROVISION_FINALIZATION |
| 373 | = "android.app.action.PROVISION_FINALIZATION"; |
| 374 | |
| 375 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 376 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 377 | * |
| 378 | * @hide |
| 379 | */ |
| 380 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 381 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 382 | |
| 383 | /** |
| 384 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 385 | * |
| 386 | * @hide |
| 387 | */ |
| 388 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 389 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 390 | |
| 391 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 392 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 393 | * |
| 394 | * @hide |
| 395 | */ |
| 396 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 397 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 398 | |
| 399 | /** |
| 400 | * Extra for shared bugreport's SHA-256 hash. |
| 401 | * |
| 402 | * @hide |
| 403 | */ |
| 404 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 405 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 406 | |
| 407 | /** |
| 408 | * Extra for remote bugreport notification shown type. |
| 409 | * |
| 410 | * @hide |
| 411 | */ |
| 412 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 413 | "android.app.extra.bugreport_notification_type"; |
| 414 | |
| 415 | /** |
| 416 | * Notification type for a started remote bugreport flow. |
| 417 | * |
| 418 | * @hide |
| 419 | */ |
| 420 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 421 | |
| 422 | /** |
| 423 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 424 | * being taken. |
| 425 | * |
| 426 | * @hide |
| 427 | */ |
| 428 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 429 | |
| 430 | /** |
| 431 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 432 | * |
| 433 | * @hide |
| 434 | */ |
| 435 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 436 | |
| 437 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 438 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 439 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 440 | * |
| 441 | * @hide |
| 442 | */ |
| 443 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 444 | |
| 445 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 446 | * 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] | 447 | * allows a mobile device management application or NFC programmer application which starts |
| 448 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 449 | * <p> |
| 450 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 451 | * sends the intent to pass data to itself on the newly created profile. |
| 452 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 453 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 454 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 455 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 456 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 457 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 458 | * management application after provisioning. |
| 459 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 460 | * <p> |
| 461 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 462 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 463 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 464 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 465 | */ |
| 466 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 467 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 468 | |
| 469 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 470 | * A String extra holding the package name of the mobile device management application that |
| 471 | * will be set as the profile owner or device owner. |
| 472 | * |
| 473 | * <p>If an application starts provisioning directly via an intent with action |
| 474 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 475 | * application that started provisioning. The package will be set as profile owner in that case. |
| 476 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 477 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 478 | * 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] | 479 | * |
| 480 | * <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] | 481 | * 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] | 482 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 483 | * @see DeviceAdminReceiver |
| 484 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 485 | * supported, but only if there is only one device admin receiver in the package that requires |
| 486 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 487 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 488 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 489 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 490 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 491 | |
| 492 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 493 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 494 | * application that will be set as the profile owner or device owner and active admin. |
| 495 | * |
| 496 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 497 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 498 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 499 | * 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] | 500 | * |
| 501 | * <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] | 502 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 503 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 504 | * {@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] | 505 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 506 | * |
| 507 | * @see DeviceAdminReceiver |
| 508 | */ |
| 509 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 510 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 511 | |
| 512 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 513 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 514 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 515 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 516 | * |
| 517 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 518 | */ |
| 519 | |
| 520 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 521 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 522 | |
| 523 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 524 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 525 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 526 | * the account will not be removed from the primary user after it is migrated to the newly |
| 527 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 528 | * |
| 529 | * <p> Defaults to {@code false} |
| 530 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 531 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 532 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 533 | */ |
| 534 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 535 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 536 | |
| 537 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 538 | * A String extra that, holds the email address of the account which a managed profile is |
| 539 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 540 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 541 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 542 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 543 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 544 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 545 | * contains this extra, it is forwarded in the |
| 546 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 547 | * device management application that was set as the profile owner during provisioning. |
| 548 | * 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] | 549 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 550 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 551 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 552 | |
| 553 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 554 | * A integer extra indicating the predominant color to show during the provisioning. |
| 555 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 556 | * |
| 557 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 558 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 559 | */ |
| 560 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 561 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 562 | |
| 563 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 564 | * 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] | 565 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 566 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 567 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 568 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 569 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 570 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 571 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 572 | |
| 573 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 574 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 575 | * will be set to. |
| 576 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 577 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 578 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 579 | */ |
| 580 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 581 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 582 | |
| 583 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 584 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 585 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 586 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 587 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 588 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 589 | */ |
| 590 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 591 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 595 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 596 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 597 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 598 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 599 | */ |
| 600 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 601 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | |
| 603 | /** |
| 604 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 605 | * owner provisioning for downloading the mobile device management application. |
| 606 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 607 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 608 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 609 | */ |
| 610 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 611 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | |
| 613 | /** |
| 614 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 615 | * is hidden or not. |
| 616 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 617 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 618 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 619 | */ |
| 620 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 621 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 625 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 626 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 627 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 628 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 629 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 630 | */ |
| 631 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 632 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 633 | |
| 634 | /** |
| 635 | * A String extra holding the password of the wifi network in |
| 636 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 637 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 638 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 639 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 640 | */ |
| 641 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 642 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 643 | |
| 644 | /** |
| 645 | * A String extra holding the proxy host for the wifi network in |
| 646 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 647 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 648 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 649 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 650 | */ |
| 651 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 652 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 653 | |
| 654 | /** |
| 655 | * An int extra holding the proxy port for the wifi network in |
| 656 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 657 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 658 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 659 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 660 | */ |
| 661 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 662 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 663 | |
| 664 | /** |
| 665 | * A String extra holding the proxy bypass for the wifi network in |
| 666 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 667 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 668 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 669 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 670 | */ |
| 671 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 672 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 673 | |
| 674 | /** |
| 675 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 676 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 677 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 678 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 679 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 680 | */ |
| 681 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 682 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 683 | |
| 684 | /** |
| 685 | * A String extra holding a url that specifies the download location of the device admin |
| 686 | * package. When not provided it is assumed that the device admin package is already installed. |
| 687 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 688 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 689 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 690 | */ |
| 691 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 692 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 693 | |
| 694 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 695 | * A String extra holding the localized name of the organization under management. |
| 696 | * |
| 697 | * The name is displayed only during provisioning. |
| 698 | * |
| 699 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 700 | * |
| 701 | * @hide |
| 702 | */ |
| 703 | @SystemApi |
| 704 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 705 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 706 | |
| 707 | /** |
| 708 | * A String extra holding a url to the website of the device's provider. The website can be |
| 709 | * opened in a browser during provisioning. |
| 710 | * |
| 711 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 712 | * |
| 713 | * @hide |
| 714 | */ |
| 715 | @SystemApi |
| 716 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 717 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 718 | |
| 719 | /** |
| 720 | * A String extra holding the localized name of the device admin package. It should be the same |
| 721 | * as the app label of the package. |
| 722 | * |
| 723 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 724 | * |
| 725 | * @hide |
| 726 | */ |
| 727 | @SystemApi |
| 728 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 729 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 730 | |
| 731 | /** |
| 732 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 733 | * shown during the provisioning. |
| 734 | * <h5>The following URI schemes are accepted:</h5> |
| 735 | * <ul> |
| 736 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 737 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 738 | * </ul> |
| 739 | * |
| 740 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 741 | * pixel density for the device. |
| 742 | * |
| 743 | * <p> If a content: URI is passed, the intent should have the flag |
| 744 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 745 | * {@link android.content.ClipData} of the intent too. |
| 746 | * |
| 747 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 748 | * |
| 749 | * @hide |
| 750 | */ |
| 751 | @SystemApi |
| 752 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 753 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 754 | |
| 755 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 756 | * An int extra holding a minimum required version code for the device admin package. If the |
| 757 | * device admin is already installed on the device, it will only be re-downloaded from |
| 758 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 759 | * installed package is less than this version code. |
| 760 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 761 | * <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] | 762 | * provisioning via an NFC bump. |
| 763 | */ |
| 764 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 765 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 766 | |
| 767 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 768 | * A String extra holding a http cookie header which should be used in the http request to the |
| 769 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 770 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 771 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 772 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 773 | */ |
| 774 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 775 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 776 | |
| 777 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 778 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 779 | * the file at download location specified in |
| 780 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 781 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 782 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 783 | * 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] | 784 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 785 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 786 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 787 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 788 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 789 | * |
| 790 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 791 | * 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] | 792 | * 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] | 793 | * 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] | 794 | */ |
| 795 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 796 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 797 | |
| 798 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 799 | * 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] | 800 | * android package archive at the download location specified in {@link |
| 801 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 802 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 803 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 804 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 805 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 806 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 807 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 808 | * 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] | 809 | * the download location. If the checksum does not match an error will be shown to the user and |
| 810 | * the user will be asked to factory reset the device. |
| 811 | * |
| 812 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 813 | * provisioning via an NFC bump. |
| 814 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 815 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 816 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 817 | |
| 818 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 819 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 820 | * has completed successfully. |
| 821 | * |
| 822 | * <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] | 823 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 824 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 825 | * <p>This intent will contain the following extras |
| 826 | * <ul> |
| 827 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 828 | * profile.</li> |
| 829 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 830 | * be migrated at provisioning time, if any.</li> |
| 831 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 832 | */ |
| 833 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 834 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 835 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 836 | |
| 837 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 838 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 839 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 840 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 841 | * delivered faster as it's an activity intent. |
| 842 | * |
| 843 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 844 | * the device owner case the profile is the primary user. |
| 845 | * |
| 846 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 847 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 848 | */ |
| 849 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 850 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 851 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 852 | |
| 853 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 854 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 855 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 856 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 857 | * <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] | 858 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 859 | * |
| 860 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 861 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 862 | */ |
| 863 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 864 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 865 | |
| 866 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 867 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 868 | * provisioning. If this extra is not passed, a default image will be shown. |
| 869 | * <h5>The following URI schemes are accepted:</h5> |
| 870 | * <ul> |
| 871 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 872 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 873 | * </ul> |
| 874 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 875 | * <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] | 876 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 877 | * |
| 878 | * <p> If a content: URI is passed, the intent should have the flag |
| 879 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 880 | * {@link android.content.ClipData} of the intent too. |
| 881 | * |
| 882 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 883 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 884 | */ |
| 885 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 886 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 887 | |
| 888 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 889 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 890 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 891 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 892 | * content. |
| 893 | * |
| 894 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 895 | * management application (MDM), and one disclaimer from the organization. |
| 896 | * |
| 897 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 898 | * |
| 899 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 900 | * |
| 901 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 902 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 903 | */ |
| 904 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 905 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 906 | |
| 907 | /** |
| 908 | * A String extra of localized disclaimer header. |
| 909 | * |
| 910 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 911 | * or the organization name. |
| 912 | * |
| 913 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
| 914 | */ |
| 915 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 916 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 917 | |
| 918 | /** |
| 919 | * A {@link Uri} extra pointing to disclaimer content. |
| 920 | * |
| 921 | * <h5>The following URI schemes are accepted:</h5> |
| 922 | * <ul> |
| 923 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 924 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 925 | * </ul> |
| 926 | * |
| 927 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 928 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 929 | * {@link android.widget.TextView}. |
| 930 | * |
| 931 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 932 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 933 | * {@link android.content.ClipData} of the intent too. |
| 934 | * |
| 935 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
| 936 | */ |
| 937 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 938 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 939 | |
| 940 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 941 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 942 | * during setup-wizard. |
| 943 | * |
| 944 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 945 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 946 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 947 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 948 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 949 | * |
| 950 | * @hide |
| 951 | */ |
| 952 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 953 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 954 | |
| 955 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 956 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 957 | * skipped. If unspecified, defaults to {@code false}. |
| 958 | * |
| 959 | * It can only be used by an existing device owner trying to create a managed profile via |
| 960 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 961 | */ |
| 962 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 963 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 964 | |
| 965 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 966 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 967 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 968 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 969 | * A device owner has full control over the device. The device owner can not be modified by the |
| 970 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 971 | * reset. |
| 972 | * |
| 973 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 974 | * employee or client. |
| 975 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 976 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 977 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 978 | * <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] | 979 | * contains the following properties: |
| 980 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 981 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 982 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 983 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 984 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 985 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 986 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 987 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 988 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 989 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 990 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 991 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 992 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 993 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 994 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 995 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 996 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 997 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 998 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 999 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1000 | * 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] | 1001 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1002 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1003 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1004 | */ |
| 1005 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1006 | = "application/com.android.managedprovisioning"; |
| 1007 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1008 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1009 | * Activity action: ask the user to add a new device administrator to the system. |
| 1010 | * The desired policy is the ComponentName of the policy in the |
| 1011 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1012 | * bring the user through adding the device administrator to the system (or |
| 1013 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1014 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1015 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1016 | * field to provide the user with additional explanation (in addition |
| 1017 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1018 | * |
| 1019 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1020 | * user intervention). However, if your administrator has been updated and is requesting |
| 1021 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1022 | * 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] | 1023 | */ |
| 1024 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1025 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1026 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1027 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1028 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1029 | * @hide |
| 1030 | * 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] | 1031 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1032 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1033 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1034 | * 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] | 1035 | * to remotely control restrictions on the user. |
| 1036 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1037 | * <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] | 1038 | * result of whether or not the user approved the action. If approved, the result will |
| 1039 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1040 | * as a profile owner. |
| 1041 | * |
| 1042 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1043 | * field to provide the user with additional explanation (in addition |
| 1044 | * to your component's description) about what is being added. |
| 1045 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1046 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1047 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1048 | */ |
| 1049 | @SystemApi |
| 1050 | public static final String ACTION_SET_PROFILE_OWNER |
| 1051 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1052 | |
| 1053 | /** |
| 1054 | * @hide |
| 1055 | * Name of the profile owner admin that controls the user. |
| 1056 | */ |
| 1057 | @SystemApi |
| 1058 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1059 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1060 | |
| 1061 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1062 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1063 | * 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] | 1064 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1065 | * @hide |
| 1066 | */ |
| 1067 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1068 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1069 | |
| 1070 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1071 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1072 | * |
| 1073 | * This broadcast is sent only to the primary user. |
| 1074 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1075 | */ |
| 1076 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1077 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1078 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1079 | |
| 1080 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1081 | * The ComponentName of the administrator component. |
| 1082 | * |
| 1083 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1084 | */ |
| 1085 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1086 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1087 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1088 | * An optional CharSequence providing additional explanation for why the |
| 1089 | * admin is being added. |
| 1090 | * |
| 1091 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1092 | */ |
| 1093 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1094 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1095 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1096 | * Activity action: have the user enter a new password. This activity should |
| 1097 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1098 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1099 | * enter a new password that meets the current requirements. You can use |
| 1100 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1101 | * have the user select a new password in order to meet the current |
| 1102 | * constraints. Upon being resumed from this activity, you can check the new |
| 1103 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1104 | * |
| 1105 | * If the intent is launched from within a managed profile with a profile |
| 1106 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1107 | * this will trigger entering a new password for the parent of the profile. |
| 1108 | * For all other cases it will trigger entering a new password for the user |
| 1109 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1110 | * |
| 1111 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1112 | */ |
| 1113 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1114 | public static final String ACTION_SET_NEW_PASSWORD |
| 1115 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1116 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1117 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1118 | * Activity action: have the user enter a new password for the parent profile. |
| 1119 | * If the intent is launched from within a managed profile, this will trigger |
| 1120 | * entering a new password for the parent of the profile. In all other cases |
| 1121 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1122 | */ |
| 1123 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1124 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1125 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1126 | |
| 1127 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1128 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1129 | * Network logging was enabled and the user tapped the notification. |
| 1130 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1131 | * @hide |
| 1132 | */ |
| 1133 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1134 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1135 | |
| 1136 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1137 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1138 | * the parent profile to access intents sent from the managed profile. |
| 1139 | * That is, when an app in the managed profile calls |
| 1140 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1141 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1142 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1143 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1144 | |
| 1145 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1146 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1147 | * the managed profile to access intents sent from the parent profile. |
| 1148 | * That is, when an app in the parent profile calls |
| 1149 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1150 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1151 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1152 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1153 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1154 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1155 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1156 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1157 | */ |
| 1158 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1159 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1160 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1161 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1162 | /** |
| 1163 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1164 | * Already granted or denied permissions are not affected by this. |
| 1165 | */ |
| 1166 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1167 | |
| 1168 | /** |
| 1169 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1170 | * Already granted or denied permissions are not affected by this. |
| 1171 | */ |
| 1172 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1173 | |
| 1174 | /** |
| 1175 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1176 | * Already granted or denied permissions are not affected by this. |
| 1177 | */ |
| 1178 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1179 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1180 | /** |
| 1181 | * Runtime permission state: The user can manage the permission |
| 1182 | * through the UI. |
| 1183 | */ |
| 1184 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1185 | |
| 1186 | /** |
| 1187 | * Runtime permission state: The permission is granted to the app |
| 1188 | * and the user cannot manage the permission through the UI. |
| 1189 | */ |
| 1190 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1191 | |
| 1192 | /** |
| 1193 | * Runtime permission state: The permission is denied to the app |
| 1194 | * and the user cannot manage the permission through the UI. |
| 1195 | */ |
| 1196 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1197 | |
| 1198 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1199 | * No management for current user in-effect. This is the default. |
| 1200 | * @hide |
| 1201 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1202 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1203 | public static final int STATE_USER_UNMANAGED = 0; |
| 1204 | |
| 1205 | /** |
| 1206 | * Management partially setup, user setup needs to be completed. |
| 1207 | * @hide |
| 1208 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1209 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1210 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1211 | |
| 1212 | /** |
| 1213 | * Management partially setup, user setup completed. |
| 1214 | * @hide |
| 1215 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1216 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1217 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1218 | |
| 1219 | /** |
| 1220 | * Management setup and active on current user. |
| 1221 | * @hide |
| 1222 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1223 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1224 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1225 | |
| 1226 | /** |
| 1227 | * Management partially setup on a managed profile. |
| 1228 | * @hide |
| 1229 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1230 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1231 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1232 | |
| 1233 | /** |
| 1234 | * @hide |
| 1235 | */ |
| 1236 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1237 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1238 | @Retention(RetentionPolicy.SOURCE) |
| 1239 | public @interface UserProvisioningState {} |
| 1240 | |
| 1241 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1242 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1243 | * |
| 1244 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1245 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1246 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1247 | * |
| 1248 | * @hide |
| 1249 | */ |
| 1250 | public static final int CODE_OK = 0; |
| 1251 | |
| 1252 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1253 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1254 | * |
| 1255 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1256 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1257 | * owner. |
| 1258 | * |
| 1259 | * @hide |
| 1260 | */ |
| 1261 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1262 | |
| 1263 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1264 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1265 | * |
| 1266 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1267 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1268 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1269 | * |
| 1270 | * @hide |
| 1271 | */ |
| 1272 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1273 | |
| 1274 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1275 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1276 | * |
| 1277 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1278 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1279 | * |
| 1280 | * @hide |
| 1281 | */ |
| 1282 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1283 | |
| 1284 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1285 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1286 | * |
| 1287 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1288 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1289 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1290 | * |
| 1291 | * @hide |
| 1292 | */ |
| 1293 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1294 | |
| 1295 | /** |
| 1296 | * Code used to indicate that the device also has a user other than the system user. |
| 1297 | * |
| 1298 | * @hide |
| 1299 | */ |
| 1300 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1301 | |
| 1302 | /** |
| 1303 | * Code used to indicate that device has an account that prevents provisioning. |
| 1304 | * |
| 1305 | * @hide |
| 1306 | */ |
| 1307 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1308 | |
| 1309 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1310 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1311 | * |
| 1312 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1313 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1314 | * |
| 1315 | * @hide |
| 1316 | */ |
| 1317 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1318 | |
| 1319 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1320 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1321 | * |
| 1322 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1323 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1324 | * when the device is a watch and is already paired. |
| 1325 | * |
| 1326 | * @hide |
| 1327 | */ |
| 1328 | public static final int CODE_HAS_PAIRED = 8; |
| 1329 | |
| 1330 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1331 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1332 | * |
| 1333 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1334 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1335 | * |
| 1336 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1337 | * @hide |
| 1338 | */ |
| 1339 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1340 | |
| 1341 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1342 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1343 | * |
| 1344 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1345 | * |
| 1346 | * @hide |
| 1347 | */ |
| 1348 | public static final int CODE_SYSTEM_USER = 10; |
| 1349 | |
| 1350 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1351 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1352 | * |
| 1353 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1354 | * managed profiles. |
| 1355 | * |
| 1356 | * @hide |
| 1357 | */ |
| 1358 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1359 | |
| 1360 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1361 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1362 | * |
| 1363 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1364 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1365 | * user. |
| 1366 | * |
| 1367 | * @hide |
| 1368 | */ |
| 1369 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1370 | |
| 1371 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1372 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1373 | * |
| 1374 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1375 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1376 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1377 | * admins. |
| 1378 | * |
| 1379 | * @hide |
| 1380 | */ |
| 1381 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1382 | |
| 1383 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1384 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1385 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1386 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1387 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1388 | * |
| 1389 | * @hide |
| 1390 | */ |
| 1391 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1392 | |
| 1393 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1394 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1395 | * |
| 1396 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1397 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1398 | * |
| 1399 | * @hide |
| 1400 | */ |
| 1401 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1402 | |
| 1403 | /** |
| 1404 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1405 | * conditions. |
| 1406 | * |
| 1407 | * @hide |
| 1408 | */ |
| 1409 | @Retention(RetentionPolicy.SOURCE) |
| 1410 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1411 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1412 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1413 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1414 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1415 | public @interface ProvisioningPreCondition {} |
| 1416 | |
| 1417 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1418 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1419 | * |
| 1420 | * @param admin The administrator component to check for. |
| 1421 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1422 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1423 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1424 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1425 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1426 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * @see #isAdminActive(ComponentName) |
| 1431 | * @hide |
| 1432 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1433 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1434 | if (mService != null) { |
| 1435 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1436 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1437 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1438 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | return false; |
| 1442 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1443 | /** |
| 1444 | * Return true if the given administrator component is currently being removed |
| 1445 | * for the user. |
| 1446 | * @hide |
| 1447 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1448 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1449 | if (mService != null) { |
| 1450 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1451 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1452 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1453 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | return false; |
| 1457 | } |
| 1458 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1459 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1460 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1461 | * Return a list of all currently active device administrators' component |
| 1462 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1463 | * returned. |
| 1464 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1465 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1466 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1467 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | /** |
| 1471 | * @see #getActiveAdmins() |
| 1472 | * @hide |
| 1473 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1474 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1475 | if (mService != null) { |
| 1476 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1477 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1478 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1479 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1480 | } |
| 1481 | } |
| 1482 | return null; |
| 1483 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1484 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1485 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1486 | * Used by package administration code to determine if a package can be stopped |
| 1487 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1488 | * @hide |
| 1489 | */ |
| 1490 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1491 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1492 | } |
| 1493 | |
| 1494 | /** |
| 1495 | * Used by package administration code to determine if a package can be stopped |
| 1496 | * or uninstalled. |
| 1497 | * @hide |
| 1498 | */ |
| 1499 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1500 | if (mService != null) { |
| 1501 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1502 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1503 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1504 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | return false; |
| 1508 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1509 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1510 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1511 | * Remove a current administration component. This can only be called |
| 1512 | * by the application that owns the administration component; if you |
| 1513 | * try to remove someone else's component, a security exception will be |
| 1514 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1515 | * |
| 1516 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1517 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1518 | * |
| 1519 | * @param admin The administration compononent to remove. |
| 1520 | * @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] | 1521 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1522 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1523 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1524 | if (mService != null) { |
| 1525 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1526 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1527 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1528 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1532 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1533 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1534 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1535 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1536 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1537 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1538 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1539 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1540 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1541 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1542 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1543 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1544 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1545 | if (mService != null) { |
| 1546 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1547 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1548 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1549 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | return false; |
| 1553 | } |
| 1554 | |
| 1555 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1556 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1557 | * |
| 1558 | * @hide |
| 1559 | */ |
| 1560 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1561 | if (mService != null) { |
| 1562 | try { |
| 1563 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1564 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1565 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | return false; |
| 1569 | } |
| 1570 | |
| 1571 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1572 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1573 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1574 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1575 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1576 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1577 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1578 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1579 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1580 | * recognition technology. This implies technologies that can recognize the identity of |
| 1581 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1582 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1583 | */ |
| 1584 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1585 | |
| 1586 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1587 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1588 | * 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] | 1589 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1590 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1591 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1592 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1593 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1594 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1595 | * password containing at least numeric characters. Note that quality |
| 1596 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1597 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1598 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1599 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1600 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1601 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1602 | * password containing at least numeric characters with no repeating (4444) |
| 1603 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1604 | * constants are ordered so that higher values are more restrictive. |
| 1605 | */ |
| 1606 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1607 | |
| 1608 | /** |
| 1609 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1610 | * password containing at least alphabetic (or other symbol) characters. |
| 1611 | * Note that quality constants are ordered so that higher values are more |
| 1612 | * restrictive. |
| 1613 | */ |
| 1614 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1615 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1616 | /** |
| 1617 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1618 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1619 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1620 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1621 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1622 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1623 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1624 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1625 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1626 | * password containing at least a letter, a numerical digit and a special |
| 1627 | * symbol, by default. With this password quality, passwords can be |
| 1628 | * restricted to contain various sets of characters, like at least an |
| 1629 | * uppercase letter, etc. These are specified using various methods, |
| 1630 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1631 | * that quality constants are ordered so that higher values are more |
| 1632 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1633 | */ |
| 1634 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1635 | |
| 1636 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1637 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1638 | * modify password. In case this password quality is set, the password is |
| 1639 | * managed by a profile owner. The profile owner can set any password, |
| 1640 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1641 | * that quality constants are ordered so that higher values are more |
| 1642 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1643 | * the highest. |
| 1644 | * @hide |
| 1645 | */ |
| 1646 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1647 | |
| 1648 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1649 | * @hide |
| 1650 | * |
| 1651 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1652 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1653 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1654 | * used by authenticator to exempt their accounts from this: |
| 1655 | * |
| 1656 | * <ul> |
| 1657 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1658 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1659 | * <application> tag in the manifest. |
| 1660 | * |
| 1661 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1662 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1663 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1664 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1665 | * if any of the accounts have it. |
| 1666 | * </ul> |
| 1667 | */ |
| 1668 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1669 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1670 | |
| 1671 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
| 1672 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1673 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1674 | |
| 1675 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1676 | * Called by an application that is administering the device to set the password restrictions it |
| 1677 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1678 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1679 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1680 | * 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] | 1681 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1682 | * <p> |
| 1683 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1684 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1685 | * considerations) is the one that is in effect. |
| 1686 | * <p> |
| 1687 | * The calling device admin must have requested |
| 1688 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1689 | * not, a security exception will be thrown. |
| 1690 | * <p> |
| 1691 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1692 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1693 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1694 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1695 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1696 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1697 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1698 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1699 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1700 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1701 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1702 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1703 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1704 | if (mService != null) { |
| 1705 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1706 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1707 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1708 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1712 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1713 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1714 | * 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] | 1715 | * 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] | 1716 | * a separate challenge are not taken into account. |
| 1717 | * |
| 1718 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1719 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1720 | * restrictions on the parent profile. |
| 1721 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1722 | * @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] | 1723 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1724 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1725 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1726 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1730 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1731 | if (mService != null) { |
| 1732 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1733 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1734 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1735 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1736 | } |
| 1737 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1738 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1739 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1740 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1741 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1742 | * Called by an application that is administering the device to set the minimum allowed password |
| 1743 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1744 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1745 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1746 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1747 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1748 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1749 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1750 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1751 | * {@link #setPasswordQuality}. |
| 1752 | * <p> |
| 1753 | * The calling device admin must have requested |
| 1754 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1755 | * not, a security exception will be thrown. |
| 1756 | * <p> |
| 1757 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1758 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1759 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1760 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1761 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1762 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1763 | * restriction. |
| 1764 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1765 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1766 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1767 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1768 | if (mService != null) { |
| 1769 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1770 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1771 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1772 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1773 | } |
| 1774 | } |
| 1775 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1776 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1777 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1778 | * 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] | 1779 | * 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] | 1780 | * a separate challenge are not taken into account. |
| 1781 | * |
| 1782 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1783 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1784 | * restrictions on the parent profile. |
| 1785 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1786 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1787 | * @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] | 1788 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1789 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1790 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1791 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1795 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1796 | if (mService != null) { |
| 1797 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1798 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1799 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1800 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1801 | } |
| 1802 | } |
| 1803 | return 0; |
| 1804 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1805 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1806 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1807 | * Called by an application that is administering the device to set the minimum number of upper |
| 1808 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1809 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1810 | * current password will remain until the user has set a new one, so the change does not take |
| 1811 | * place immediately. To prompt the user for a new password, use |
| 1812 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1813 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1814 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1815 | * <p> |
| 1816 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1817 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1818 | * not, a security exception will be thrown. |
| 1819 | * <p> |
| 1820 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1821 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1822 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1823 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1824 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1825 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1826 | * A value of 0 means there is no restriction. |
| 1827 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1828 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1829 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1830 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1831 | if (mService != null) { |
| 1832 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1833 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1834 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1835 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1841 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1842 | * 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] | 1843 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1844 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1845 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1846 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1847 | * and only applies when the password quality is |
| 1848 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1849 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1850 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1851 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1852 | * restrictions on the parent profile. |
| 1853 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1854 | * @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] | 1855 | * aggregate all admins. |
| 1856 | * @return The minimum number of upper case letters required in the |
| 1857 | * password. |
| 1858 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1859 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1860 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1864 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1865 | if (mService != null) { |
| 1866 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1867 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1868 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1869 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1870 | } |
| 1871 | } |
| 1872 | return 0; |
| 1873 | } |
| 1874 | |
| 1875 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1876 | * Called by an application that is administering the device to set the minimum number of lower |
| 1877 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1878 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1879 | * current password will remain until the user has set a new one, so the change does not take |
| 1880 | * place immediately. To prompt the user for a new password, use |
| 1881 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1882 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1883 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1884 | * <p> |
| 1885 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1886 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1887 | * not, a security exception will be thrown. |
| 1888 | * <p> |
| 1889 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1890 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1891 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1892 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1893 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1894 | * @param length The new desired minimum number of lower case letters required in the password. |
| 1895 | * A value of 0 means there is no restriction. |
| 1896 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1897 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1898 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1899 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1900 | if (mService != null) { |
| 1901 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1902 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1903 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1904 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1905 | } |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1910 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1911 | * 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] | 1912 | * and its participating profiles. Restrictions on profiles that have |
| 1913 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1914 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1915 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1916 | * and only applies when the password quality is |
| 1917 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1918 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1919 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1920 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1921 | * restrictions on the parent profile. |
| 1922 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1923 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1924 | * aggregate all admins. |
| 1925 | * @return The minimum number of lower case letters required in the |
| 1926 | * password. |
| 1927 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1928 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1929 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1933 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1934 | if (mService != null) { |
| 1935 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1936 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1937 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1938 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | return 0; |
| 1942 | } |
| 1943 | |
| 1944 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1945 | * Called by an application that is administering the device to set the minimum number of |
| 1946 | * letters required in the password. After setting this, the user will not be able to enter a |
| 1947 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1948 | * password will remain until the user has set a new one, so the change does not take place |
| 1949 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1950 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1951 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1952 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1953 | * <p> |
| 1954 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1955 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1956 | * not, a security exception will be thrown. |
| 1957 | * <p> |
| 1958 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1959 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1960 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1961 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1962 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1963 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1964 | * 0 means there is no restriction. |
| 1965 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1966 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1967 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1968 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1969 | if (mService != null) { |
| 1970 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1971 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1972 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1973 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1979 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1980 | * 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] | 1981 | * and its participating profiles. Restrictions on profiles that have |
| 1982 | * a separate challenge are not taken into account. |
| 1983 | * This is the same value as set by |
| 1984 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1985 | * and only applies when the password quality is |
| 1986 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1987 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1988 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1989 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1990 | * restrictions on the parent profile. |
| 1991 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1992 | * @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] | 1993 | * aggregate all admins. |
| 1994 | * @return The minimum number of letters required in the password. |
| 1995 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1996 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1997 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2001 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2002 | if (mService != null) { |
| 2003 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2004 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2005 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2006 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2007 | } |
| 2008 | } |
| 2009 | return 0; |
| 2010 | } |
| 2011 | |
| 2012 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2013 | * Called by an application that is administering the device to set the minimum number of |
| 2014 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2015 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2016 | * current password will remain until the user has set a new one, so the change does not take |
| 2017 | * place immediately. To prompt the user for a new password, use |
| 2018 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2019 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2020 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2021 | * <p> |
| 2022 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2023 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2024 | * not, a security exception will be thrown. |
| 2025 | * <p> |
| 2026 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2027 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2028 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2029 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2030 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2031 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2032 | * value of 0 means there is no restriction. |
| 2033 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2034 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2035 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2036 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2037 | if (mService != null) { |
| 2038 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2039 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2040 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2041 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | /** |
| 2047 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2048 | * 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] | 2049 | * and its participating profiles. Restrictions on profiles that have |
| 2050 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2051 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2052 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2053 | * and only applies when the password quality is |
| 2054 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2055 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2056 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2057 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2058 | * restrictions on the parent profile. |
| 2059 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2060 | * @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] | 2061 | * aggregate all admins. |
| 2062 | * @return The minimum number of numerical digits required in the password. |
| 2063 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2064 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2065 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2069 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2070 | if (mService != null) { |
| 2071 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2072 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2073 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2074 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | return 0; |
| 2078 | } |
| 2079 | |
| 2080 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2081 | * Called by an application that is administering the device to set the minimum number of |
| 2082 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2083 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2084 | * password will remain until the user has set a new one, so the change does not take place |
| 2085 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2086 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2087 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2088 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2089 | * <p> |
| 2090 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2091 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2092 | * not, a security exception will be thrown. |
| 2093 | * <p> |
| 2094 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2095 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2096 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2097 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2098 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2099 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2100 | * 0 means there is no restriction. |
| 2101 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2102 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2103 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2104 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2105 | if (mService != null) { |
| 2106 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2107 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2108 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2109 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2115 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2116 | * 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] | 2117 | * and its participating profiles. Restrictions on profiles that have |
| 2118 | * a separate challenge are not taken into account. This is the same value as |
| 2119 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2120 | * and only applies when the password quality is |
| 2121 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2122 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2123 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2124 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2125 | * restrictions on the parent profile. |
| 2126 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2127 | * @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] | 2128 | * aggregate all admins. |
| 2129 | * @return The minimum number of symbols required in the password. |
| 2130 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2131 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2132 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2136 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2137 | if (mService != null) { |
| 2138 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2139 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2140 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2141 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2142 | } |
| 2143 | } |
| 2144 | return 0; |
| 2145 | } |
| 2146 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2147 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2148 | * Called by an application that is administering the device to set the minimum number of |
| 2149 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2150 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2151 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2152 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2153 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2154 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2155 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2156 | * <p> |
| 2157 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2158 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2159 | * not, a security exception will be thrown. |
| 2160 | * <p> |
| 2161 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2162 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2163 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2164 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2165 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2166 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2167 | * 0 means there is no restriction. |
| 2168 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2169 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2170 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2171 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2172 | if (mService != null) { |
| 2173 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2174 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2175 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2176 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2182 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2183 | * 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] | 2184 | * and its participating profiles. Restrictions on profiles that have |
| 2185 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2186 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2187 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2188 | * and only applies when the password quality is |
| 2189 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2190 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2191 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2192 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2193 | * restrictions on the parent profile. |
| 2194 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2195 | * @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] | 2196 | * aggregate all admins. |
| 2197 | * @return The minimum number of letters required in the password. |
| 2198 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2199 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2200 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2204 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2205 | if (mService != null) { |
| 2206 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2207 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2208 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2209 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2210 | } |
| 2211 | } |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2215 | /** |
| 2216 | * Called by an application that is administering the device to set the length of the password |
| 2217 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2218 | * same as any password in the history. Note that the current password will remain until the |
| 2219 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2220 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2221 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2222 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2223 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2224 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2225 | * <p> |
| 2226 | * The calling device admin must have requested |
| 2227 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2228 | * not, a security exception will be thrown. |
| 2229 | * <p> |
| 2230 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2231 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2232 | * profile. |
| 2233 | * |
| 2234 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2235 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2236 | * restriction. |
| 2237 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2238 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2240 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2241 | if (mService != null) { |
| 2242 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2243 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2244 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2245 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2251 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2252 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2253 | * device password (for all admins). |
| 2254 | * <p> |
| 2255 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2256 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2257 | * 432000000 ms for timeout. |
| 2258 | * <p> |
| 2259 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2260 | * <p> |
| 2261 | * The calling device admin must have requested |
| 2262 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2263 | * not, a security exception will be thrown. |
| 2264 | * <p> |
| 2265 | * Note that setting the password will automatically reset the expiration time for all active |
| 2266 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2267 | * <p> |
| 2268 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2269 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2270 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2271 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2272 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2273 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2274 | * there is no restriction (unlimited). |
| 2275 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2276 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2277 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2278 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2279 | if (mService != null) { |
| 2280 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2281 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2282 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2283 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2289 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2290 | * recurring expiration timeout provided in the call to |
| 2291 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2292 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2293 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2294 | * |
| 2295 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2296 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2297 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2298 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2299 | * @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] | 2300 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2301 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2302 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2303 | if (mService != null) { |
| 2304 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2305 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2306 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2307 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2308 | } |
| 2309 | } |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
| 2313 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2314 | * 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] | 2315 | * 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] | 2316 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2317 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2318 | * |
| 2319 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2320 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2321 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2322 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2323 | * @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] | 2324 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2325 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2326 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2327 | if (mService != null) { |
| 2328 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2329 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2330 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2331 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | return 0; |
| 2335 | } |
| 2336 | |
| 2337 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2338 | * 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] | 2339 | * 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] | 2340 | * have a separate challenge are not taken into account. |
| 2341 | * |
| 2342 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2343 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2344 | * restrictions on the parent profile. |
| 2345 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2346 | * @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] | 2347 | * all admins. |
| 2348 | * @return The length of the password history |
| 2349 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2350 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2351 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2355 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2356 | if (mService != null) { |
| 2357 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2358 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2359 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2360 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2361 | } |
| 2362 | } |
| 2363 | return 0; |
| 2364 | } |
| 2365 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2366 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2367 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2368 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2369 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2370 | * @return Returns the maximum length that the user can enter. |
| 2371 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2372 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2373 | // Kind-of arbitrary. |
| 2374 | return 16; |
| 2375 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2376 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2377 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2378 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2379 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2380 | * 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] | 2381 | * 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] | 2382 | * <p> |
| 2383 | * The calling device admin must have requested |
| 2384 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2385 | * not, a security exception will be thrown. |
| 2386 | * <p> |
| 2387 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2388 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2389 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2390 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2391 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2392 | * @throws SecurityException if the calling application does not own an active administrator |
| 2393 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2394 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2395 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2396 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2397 | if (mService != null) { |
| 2398 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2399 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2400 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2401 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2402 | } |
| 2403 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2404 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2405 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2406 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2407 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2408 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2409 | * 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] | 2410 | * requested by the admins of the parent user and its profiles. |
| 2411 | * |
| 2412 | * @param userHandle the userId of the profile to check the password for. |
| 2413 | * @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] | 2414 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2415 | * @hide |
| 2416 | */ |
| 2417 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2418 | if (mService != null) { |
| 2419 | try { |
| 2420 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2421 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2422 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2423 | } |
| 2424 | } |
| 2425 | return false; |
| 2426 | } |
| 2427 | |
| 2428 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2429 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2430 | * successful password entry. |
| 2431 | * <p> |
| 2432 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2433 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2434 | * password attemts for the parent user. |
| 2435 | * <p> |
| 2436 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2437 | * 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] | 2438 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2439 | * @return The number of times user has entered an incorrect password since the last correct |
| 2440 | * password entry. |
| 2441 | * @throws SecurityException if the calling application does not own an active administrator |
| 2442 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2443 | */ |
| 2444 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2445 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2446 | } |
| 2447 | |
| 2448 | /** |
| 2449 | * Retrieve the number of times the given user has failed at entering a |
| 2450 | * password since that last successful password entry. |
| 2451 | * |
| 2452 | * <p>The calling device admin must have requested |
| 2453 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2454 | * not and it is not the system uid, a security exception will be thrown. |
| 2455 | * |
| 2456 | * @hide |
| 2457 | */ |
| 2458 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2459 | if (mService != null) { |
| 2460 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2461 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2462 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2463 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | return -1; |
| 2467 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2468 | |
| 2469 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2470 | * 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] | 2471 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2472 | * @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] | 2473 | * @hide |
| 2474 | */ |
| 2475 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2476 | if (mService != null) { |
| 2477 | try { |
| 2478 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2479 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2480 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2481 | } |
| 2482 | } |
| 2483 | return false; |
| 2484 | } |
| 2485 | |
| 2486 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2487 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2488 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2489 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2490 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2491 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2492 | * <p> |
| 2493 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2494 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2495 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2496 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2497 | * immediately, and your callback will not be invoked. |
| 2498 | * <p> |
| 2499 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2500 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2501 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2502 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2503 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2504 | * @param num The number of failed password attempts at which point the device or profile will |
| 2505 | * be wiped. |
| 2506 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2507 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2508 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2509 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2510 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2511 | if (mService != null) { |
| 2512 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2513 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2514 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2515 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2516 | } |
| 2517 | } |
| 2518 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2519 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2520 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2521 | * 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] | 2522 | * 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] | 2523 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2524 | * not taken into account. |
| 2525 | * |
| 2526 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2527 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2528 | * the value for the parent profile. |
| 2529 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2530 | * @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] | 2531 | * all admins. |
| 2532 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2533 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2534 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2538 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2539 | if (mService != null) { |
| 2540 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2541 | return mService.getMaximumFailedPasswordsForWipe( |
| 2542 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2543 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2544 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2545 | } |
| 2546 | } |
| 2547 | return 0; |
| 2548 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2549 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2550 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2551 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2552 | * for the given user. So for primary user, it might return the primary or |
| 2553 | * a managed profile. For a secondary user, it would be the same as the |
| 2554 | * user passed in. |
| 2555 | * @hide Used only by Keyguard |
| 2556 | */ |
| 2557 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2558 | if (mService != null) { |
| 2559 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2560 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2561 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2562 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2563 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2564 | } |
| 2565 | } |
| 2566 | return UserHandle.USER_NULL; |
| 2567 | } |
| 2568 | |
| 2569 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2570 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2571 | * the password again until the user has entered it. |
| 2572 | */ |
| 2573 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2574 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2575 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2576 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2577 | * If the flag is set, the device can be booted without asking for user password. |
| 2578 | * The absence of this flag does not change the current boot requirements. This flag |
| 2579 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2580 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2581 | * device to factory defaults. |
| 2582 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2583 | 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] | 2584 | |
| 2585 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2586 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2587 | * individual accounts) on the user. This takes effect immediately. |
| 2588 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2589 | * <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] | 2590 | * device admins that are not device owner and not profile owner. |
| 2591 | * 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] | 2592 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2593 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2594 | * <p> |
| 2595 | * The given password must be sufficient for the current password quality and length constraints |
| 2596 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2597 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2598 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2599 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2600 | * case the currently active quality will be increased to match. |
| 2601 | * <p> |
| 2602 | * 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] | 2603 | * current password constraints allow it. <em>Note: This will not work in |
| 2604 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2605 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2606 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2607 | * <p> |
| 2608 | * The calling device admin must have requested |
| 2609 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2610 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2611 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2612 | * @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] | 2613 | * @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] | 2614 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2615 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2616 | * current constraints or if the user has not been decrypted yet. |
| 2617 | * @throws SecurityException if the calling application does not own an active administrator |
| 2618 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2619 | * @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] | 2620 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2621 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2622 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2623 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2624 | if (mService != null) { |
| 2625 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2626 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2627 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2628 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | return false; |
| 2632 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2633 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2634 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2635 | * Called by an application that is administering the device to set the maximum time for user |
| 2636 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2637 | * effect immediately. |
| 2638 | * <p> |
| 2639 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2640 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2641 | * <p> |
| 2642 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2643 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2644 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2645 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2646 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2647 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2648 | * is no restriction. |
| 2649 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2650 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2651 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2652 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2653 | if (mService != null) { |
| 2654 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2655 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2656 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2657 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2658 | } |
| 2659 | } |
| 2660 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2661 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2662 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2663 | * 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] | 2664 | * 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] | 2665 | * a separate challenge are not taken into account. |
| 2666 | * |
| 2667 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2668 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2669 | * restrictions on the parent profile. |
| 2670 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2671 | * @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] | 2672 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2673 | * @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] | 2674 | * 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] | 2675 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2676 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2677 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2681 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2682 | if (mService != null) { |
| 2683 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2684 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2685 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2686 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | return 0; |
| 2690 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2691 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2692 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2693 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2694 | * do not have a separate timeout to lock for work challenge only. |
| 2695 | * |
| 2696 | * @hide |
| 2697 | */ |
| 2698 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2699 | if (mService != null) { |
| 2700 | try { |
| 2701 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2702 | } catch (RemoteException e) { |
| 2703 | throw e.rethrowFromSystemServer(); |
| 2704 | } |
| 2705 | } |
| 2706 | return 0; |
| 2707 | } |
| 2708 | |
| 2709 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2710 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2711 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2712 | * authentication method like password, pin or pattern. |
| 2713 | * |
| 2714 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2715 | * specified timeout each time it has been successfully used. |
| 2716 | * |
| 2717 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2718 | * |
| 2719 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2720 | * |
| 2721 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2722 | * a {@link SecurityException} will be thrown. |
| 2723 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2724 | * <p>The calling device admin can verify the value it has set by calling |
| 2725 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2726 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2727 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2728 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2729 | * profile. |
| 2730 | * |
| 2731 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2732 | * @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] | 2733 | * authentication method. A value of 0 means the admin is not participating in |
| 2734 | * controlling the timeout. |
| 2735 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2736 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2737 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2738 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2739 | * |
| 2740 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2741 | */ |
| 2742 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2743 | long timeoutMs) { |
| 2744 | if (mService != null) { |
| 2745 | try { |
| 2746 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2747 | } catch (RemoteException e) { |
| 2748 | throw e.rethrowFromSystemServer(); |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | /** |
| 2754 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 2755 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 2756 | * After the returned timeout the user is required to use strong authentication method. |
| 2757 | * |
| 2758 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2759 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2760 | * restrictions on the parent profile. |
| 2761 | * |
| 2762 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 2763 | * accross all participating admins. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2764 | * @return The timeout or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2765 | */ |
| 2766 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 2767 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 2768 | } |
| 2769 | |
| 2770 | /** @hide per-user version */ |
| 2771 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 2772 | if (mService != null) { |
| 2773 | try { |
| 2774 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 2775 | } catch (RemoteException e) { |
| 2776 | throw e.rethrowFromSystemServer(); |
| 2777 | } |
| 2778 | } |
| 2779 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 2780 | } |
| 2781 | |
| 2782 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2783 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 2784 | * keyring. The user's credential will need to be entered again in order to derive the |
| 2785 | * credential encryption key that will be stored back in the keyring for future use. |
| 2786 | * <p> |
| 2787 | * This flag can only be used by a profile owner when locking a managed profile on an FBE |
| 2788 | * device. |
| 2789 | * <p> |
| 2790 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 2791 | * until they are next run to perform further actions. |
| 2792 | */ |
| 2793 | public static final int FLAG_EVICT_CE_KEY = 1; |
| 2794 | |
| 2795 | /** @hide */ |
| 2796 | @Retention(RetentionPolicy.SOURCE) |
| 2797 | @IntDef(flag=true, value={FLAG_EVICT_CE_KEY}) |
| 2798 | public @interface LockNowFlag {} |
| 2799 | |
| 2800 | /** |
| 2801 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2802 | * this call. |
| 2803 | * <p> |
| 2804 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2805 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2806 | * <p> |
| 2807 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2808 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 2809 | * <p> |
| 2810 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 2811 | * |
| 2812 | * @throws SecurityException if the calling application does not own an active administrator |
| 2813 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2814 | */ |
| 2815 | public void lockNow() { |
| 2816 | lockNow(0); |
| 2817 | } |
| 2818 | |
| 2819 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2820 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2821 | * this call. |
| 2822 | * <p> |
| 2823 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2824 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2825 | * <p> |
| 2826 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2827 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2828 | * |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2829 | * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2830 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2831 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
| 2832 | * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile |
| 2833 | * owner of a managed profile. |
| 2834 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when |
| 2835 | * locking the parent profile. |
| 2836 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a |
| 2837 | * non-FBE device. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2838 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2839 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2840 | if (mService != null) { |
| 2841 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2842 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2843 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2844 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2848 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2849 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2850 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2851 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2852 | */ |
| 2853 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2854 | |
| 2855 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2856 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2857 | * data. |
| 2858 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2859 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2860 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2861 | */ |
| 2862 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2863 | |
| 2864 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 2865 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 2866 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 2867 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 2868 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2869 | * <p> |
| 2870 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2871 | * 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] | 2872 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2873 | * @param flags Bit mask of additional options: currently supported flags are |
| 2874 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2875 | * @throws SecurityException if the calling application does not own an active administrator |
| 2876 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2877 | */ |
| 2878 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2879 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2880 | if (mService != null) { |
| 2881 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2882 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2883 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2884 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2885 | } |
| 2886 | } |
| 2887 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2888 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2889 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2890 | * Called by an application that is administering the device to set the |
| 2891 | * global proxy and exclusion list. |
| 2892 | * <p> |
| 2893 | * The calling device admin must have requested |
| 2894 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2895 | * this method; if it has not, a security exception will be thrown. |
| 2896 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2897 | * 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] | 2898 | * 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] | 2899 | * be returned. |
| 2900 | * The method can be called repeatedly by the device admin alrady setting the |
| 2901 | * proxy to update the proxy and exclusion list. |
| 2902 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2903 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2904 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2905 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2906 | * @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] | 2907 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2908 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2909 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2910 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2911 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2912 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2913 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2914 | if (proxySpec == null) { |
| 2915 | throw new NullPointerException(); |
| 2916 | } |
| 2917 | if (mService != null) { |
| 2918 | try { |
| 2919 | String hostSpec; |
| 2920 | String exclSpec; |
| 2921 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2922 | hostSpec = null; |
| 2923 | exclSpec = null; |
| 2924 | } else { |
| 2925 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2926 | throw new IllegalArgumentException(); |
| 2927 | } |
| 2928 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2929 | String hostName = sa.getHostName(); |
| 2930 | int port = sa.getPort(); |
| 2931 | StringBuilder hostBuilder = new StringBuilder(); |
| 2932 | hostSpec = hostBuilder.append(hostName) |
| 2933 | .append(":").append(Integer.toString(port)).toString(); |
| 2934 | if (exclusionList == null) { |
| 2935 | exclSpec = ""; |
| 2936 | } else { |
| 2937 | StringBuilder listBuilder = new StringBuilder(); |
| 2938 | boolean firstDomain = true; |
| 2939 | for (String exclDomain : exclusionList) { |
| 2940 | if (!firstDomain) { |
| 2941 | listBuilder = listBuilder.append(","); |
| 2942 | } else { |
| 2943 | firstDomain = false; |
| 2944 | } |
| 2945 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2946 | } |
| 2947 | exclSpec = listBuilder.toString(); |
| 2948 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2949 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2950 | != android.net.Proxy.PROXY_VALID) |
| 2951 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2952 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2953 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2954 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2955 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2956 | } |
| 2957 | } |
| 2958 | return null; |
| 2959 | } |
| 2960 | |
| 2961 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2962 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 2963 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 2964 | * unusual like general internal filtering this may be useful. On a private network where the |
| 2965 | * proxy is not accessible, you may break HTTP using this. |
| 2966 | * <p> |
| 2967 | * This method requires the caller to be the device owner. |
| 2968 | * <p> |
| 2969 | * 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] | 2970 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2971 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2972 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2973 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 2974 | * {@code null} value will clear the global HTTP proxy. |
| 2975 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2976 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2977 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2978 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2979 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2980 | if (mService != null) { |
| 2981 | try { |
| 2982 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2983 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2984 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2985 | } |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2990 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2991 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2992 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2993 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2994 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2995 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2996 | if (mService != null) { |
| 2997 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2998 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2999 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3000 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | return null; |
| 3004 | } |
| 3005 | |
| 3006 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3007 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3008 | * indicating that encryption is not supported. |
| 3009 | */ |
| 3010 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3011 | |
| 3012 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3013 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3014 | * indicating that encryption is supported, but is not currently active. |
| 3015 | */ |
| 3016 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3017 | |
| 3018 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3019 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3020 | * indicating that encryption is not currently active, but is currently |
| 3021 | * being activated. This is only reported by devices that support |
| 3022 | * encryption of data and only when the storage is currently |
| 3023 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3024 | * to become encrypted will never return this value. |
| 3025 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3026 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3027 | |
| 3028 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3029 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3030 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3031 | * <p> |
| 3032 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3033 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3034 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3035 | |
| 3036 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3037 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3038 | * indicating that encryption is active, but an encryption key has not |
| 3039 | * been set by the user. |
| 3040 | */ |
| 3041 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3042 | |
| 3043 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3044 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3045 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3046 | * <p> |
| 3047 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3048 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3049 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3050 | */ |
| 3051 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3052 | |
| 3053 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3054 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3055 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3056 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3057 | * to check encryption status. However, on some devices this activity may never return, as |
| 3058 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3059 | */ |
| 3060 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3061 | public static final String ACTION_START_ENCRYPTION |
| 3062 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3063 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3064 | * Widgets are enabled in keyguard |
| 3065 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3066 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3067 | |
| 3068 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3069 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3070 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3071 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3072 | |
| 3073 | /** |
| 3074 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3075 | */ |
| 3076 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3077 | |
| 3078 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3079 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3080 | */ |
| 3081 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3082 | |
| 3083 | /** |
| 3084 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3085 | */ |
| 3086 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3087 | |
| 3088 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3089 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3090 | * (e.g. PIN/Pattern/Password). |
| 3091 | */ |
| 3092 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3093 | |
| 3094 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3095 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3096 | */ |
| 3097 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3098 | |
| 3099 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3100 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3101 | */ |
| 3102 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3103 | |
| 3104 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3105 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3106 | */ |
| 3107 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3108 | |
| 3109 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3110 | * Called by an application that is administering the device to request that the storage system |
| 3111 | * be encrypted. |
| 3112 | * <p> |
| 3113 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3114 | * supported setting will always be used. If any device administrator requests device |
| 3115 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3116 | * 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] | 3117 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3118 | * <p> |
| 3119 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3120 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3121 | * control the encryption of any other storage areas. There is one exception: If |
| 3122 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3123 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3124 | * written to disk within the encrypted storage area. |
| 3125 | * <p> |
| 3126 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3127 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3128 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3129 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3130 | * |
| 3131 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3132 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3133 | * @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] | 3134 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3135 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3136 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3137 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3138 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3139 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3140 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3141 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3142 | if (mService != null) { |
| 3143 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3144 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3145 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3146 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3147 | } |
| 3148 | } |
| 3149 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3150 | } |
| 3151 | |
| 3152 | /** |
| 3153 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3154 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3155 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3156 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3157 | * this will return the requested encryption setting as an aggregate of all active |
| 3158 | * administrators. |
| 3159 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3160 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3161 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3162 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3163 | if (mService != null) { |
| 3164 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3165 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3166 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3167 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3168 | } |
| 3169 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3170 | return false; |
| 3171 | } |
| 3172 | |
| 3173 | /** |
| 3174 | * Called by an application that is administering the device to |
| 3175 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3176 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3177 | * Depending on the returned status code, the caller may proceed in different |
| 3178 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3179 | * storage system does not support encryption. If the |
| 3180 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3181 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3182 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3183 | * 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] | 3184 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3185 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3186 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3187 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3188 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3189 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3190 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3191 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3192 | */ |
| 3193 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3194 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3195 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | /** @hide per-user version */ |
| 3199 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3200 | if (mService != null) { |
| 3201 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3202 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3203 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3204 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3205 | } |
| 3206 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3207 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3208 | } |
| 3209 | |
| 3210 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3211 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3212 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3213 | * keep the certificate on the device. |
| 3214 | * |
| 3215 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3216 | * this certificate. |
| 3217 | * |
| 3218 | * @hide |
| 3219 | */ |
| 3220 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3221 | if (mService != null) { |
| 3222 | try { |
| 3223 | return mService.approveCaCert(alias, userHandle, approval); |
| 3224 | } catch (RemoteException e) { |
| 3225 | throw e.rethrowFromSystemServer(); |
| 3226 | } |
| 3227 | } |
| 3228 | return false; |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * Check whether a CA certificate has been approved by the device user. |
| 3233 | * |
| 3234 | * @hide |
| 3235 | */ |
| 3236 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3237 | if (mService != null) { |
| 3238 | try { |
| 3239 | return mService.isCaCertApproved(alias, userHandle); |
| 3240 | } catch (RemoteException e) { |
| 3241 | throw e.rethrowFromSystemServer(); |
| 3242 | } |
| 3243 | } |
| 3244 | return false; |
| 3245 | } |
| 3246 | |
| 3247 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3248 | * Installs the given certificate as a user CA. |
| 3249 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3250 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3251 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3252 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3253 | * |
| 3254 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3255 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3256 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3257 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3258 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3259 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3260 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3261 | if (mService != null) { |
| 3262 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3263 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3264 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3265 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3266 | } |
| 3267 | } |
| 3268 | return false; |
| 3269 | } |
| 3270 | |
| 3271 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3272 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3273 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3274 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3275 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3276 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3277 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3278 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3279 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3280 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3281 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3282 | if (mService != null) { |
| 3283 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3284 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3285 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3286 | } catch (CertificateException e) { |
| 3287 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3288 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3289 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3290 | } |
| 3291 | } |
| 3292 | } |
| 3293 | |
| 3294 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3295 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3296 | * If a user has installed any certificates by other means than device policy these will be |
| 3297 | * included too. |
| 3298 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3299 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3300 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3301 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3302 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3303 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3304 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3305 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3306 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3307 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3308 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3309 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3310 | mService.enforceCanManageCaCerts(admin); |
| 3311 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3312 | for (String alias : certStore.userAliases()) { |
| 3313 | try { |
| 3314 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3315 | } catch (CertificateException ce) { |
| 3316 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3317 | } |
| 3318 | } |
| 3319 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3320 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3327 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3328 | * means other than device policy will also be removed, except for system CA certificates. |
| 3329 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3330 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3331 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3332 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3333 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3334 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3335 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3336 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3337 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3338 | try { |
| 3339 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 3340 | .toArray(new String[0])); |
| 3341 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3342 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | /** |
| 3348 | * Returns whether this certificate is installed as a trusted CA. |
| 3349 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3350 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3351 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3352 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3353 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3354 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3355 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3356 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3357 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3358 | if (mService != null) { |
| 3359 | try { |
| 3360 | mService.enforceCanManageCaCerts(admin); |
| 3361 | return getCaCertAlias(certBuffer) != null; |
| 3362 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3363 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3364 | } catch (CertificateException ce) { |
| 3365 | Log.w(TAG, "Could not parse certificate", ce); |
| 3366 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3367 | } |
| 3368 | return false; |
| 3369 | } |
| 3370 | |
| 3371 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3372 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3373 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3374 | * the certificate and use the private key, given direct user approval. |
| 3375 | * |
| 3376 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3377 | * direct user approval. This is for security - should a certificate installer become |
| 3378 | * compromised, certificates it had already installed will be protected. |
| 3379 | * |
| 3380 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3381 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3382 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3383 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3384 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3385 | * @param privKey The private key to install. |
| 3386 | * @param cert The certificate to install. |
| 3387 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3388 | * with that alias already exists, it will be overwritten. |
| 3389 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3390 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3391 | * owner. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3392 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3393 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3394 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3395 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | /** |
| 3399 | * 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] | 3400 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3401 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3402 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3403 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3404 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3405 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3406 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3407 | * |
| 3408 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3409 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3410 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3411 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3412 | * certificate and include the chain of trust in order. This will be returned by |
| 3413 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3414 | * @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] | 3415 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3416 | * @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] | 3417 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3418 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3419 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3420 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3421 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3422 | * @see android.security.KeyChain#getCertificateChain |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3423 | */ |
| 3424 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3425 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3426 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3427 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3428 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3429 | byte[] pemChain = null; |
| 3430 | if (certs.length > 1) { |
| 3431 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3432 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3433 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3434 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3435 | return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias, |
| 3436 | requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3437 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3438 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3439 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3440 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3441 | } catch (CertificateException | IOException e) { |
| 3442 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3443 | } |
| 3444 | return false; |
| 3445 | } |
| 3446 | |
| 3447 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3448 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3449 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3450 | * |
| 3451 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3452 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3453 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3454 | * @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] | 3455 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3456 | * owner. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3457 | */ |
| 3458 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3459 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3460 | try { |
| 3461 | return mService.removeKeyPair(admin, alias); |
| 3462 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3463 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3464 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3468 | * @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] | 3469 | * doesn't exist. |
| 3470 | */ |
| 3471 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3472 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3473 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3474 | new ByteArrayInputStream(certBuffer)); |
| 3475 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3476 | } |
| 3477 | |
| 3478 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3479 | * 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] | 3480 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3481 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3482 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3483 | * <p> |
| 3484 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3485 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3486 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3487 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3488 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3489 | * 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] | 3490 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3491 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3492 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3493 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3494 | * @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] | 3495 | * access. If {@code null} is given the current package will be cleared. |
| 3496 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3497 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3498 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3499 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3500 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3501 | if (mService != null) { |
| 3502 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3503 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3504 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3505 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3511 | * Called by a profile owner or device owner to retrieve the certificate installer for the user. |
| 3512 | * null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3513 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3514 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3515 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3516 | * none is set. |
| 3517 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3518 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3519 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3520 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3521 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3522 | if (mService != null) { |
| 3523 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3524 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3525 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3526 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3527 | } |
| 3528 | } |
| 3529 | return null; |
| 3530 | } |
| 3531 | |
| 3532 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3533 | * 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] | 3534 | * specific application for the current user. |
| 3535 | * |
| 3536 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3537 | * TODO: delete once there are no longer any live references. |
| 3538 | * @hide |
| 3539 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3540 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3541 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3542 | throws NameNotFoundException, UnsupportedOperationException { |
| 3543 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3544 | } |
| 3545 | |
| 3546 | /** |
| 3547 | * 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] | 3548 | * specific application for the current user. This connection is automatically granted and |
| 3549 | * persisted after a reboot. |
| 3550 | * <p> |
| 3551 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3552 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3553 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3554 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3555 | * @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] | 3556 | * remove an existing always-on VPN configuration. |
| 3557 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3558 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3559 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3560 | * @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] | 3561 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3562 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3563 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3564 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3565 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3566 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3567 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3568 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3569 | if (mService != null) { |
| 3570 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3571 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3572 | throw new NameNotFoundException(vpnPackage); |
| 3573 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3574 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3575 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3576 | } |
| 3577 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | /** |
| 3581 | * 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] | 3582 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3583 | * 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] | 3584 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3585 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3586 | * is set. |
| 3587 | * @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] | 3588 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3589 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3590 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3591 | if (mService != null) { |
| 3592 | try { |
| 3593 | return mService.getAlwaysOnVpnPackage(admin); |
| 3594 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3595 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3596 | } |
| 3597 | } |
| 3598 | return null; |
| 3599 | } |
| 3600 | |
| 3601 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3602 | * Called by an application that is administering the device to disable all cameras on the |
| 3603 | * device, for this user. After setting this, no applications running as this user will be able |
| 3604 | * to access any cameras on the device. |
| 3605 | * <p> |
| 3606 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3607 | * <p> |
| 3608 | * The calling device admin must have requested |
| 3609 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3610 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3611 | * |
| 3612 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3613 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3614 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3615 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3616 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3617 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3618 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3619 | if (mService != null) { |
| 3620 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3621 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3622 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3623 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3624 | } |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3629 | * 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] | 3630 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3631 | * @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] | 3632 | * have disabled the camera |
| 3633 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3634 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3635 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3636 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3640 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3641 | if (mService != null) { |
| 3642 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3643 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3644 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3645 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3646 | } |
| 3647 | } |
| 3648 | return false; |
| 3649 | } |
| 3650 | |
| 3651 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3652 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3653 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 3654 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 3655 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 3656 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3657 | * |
| 3658 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3659 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3660 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3661 | * 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^] | 3662 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 3663 | * 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] | 3664 | */ |
| 3665 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3666 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3667 | if (mService != null) { |
| 3668 | try { |
| 3669 | return mService.requestBugreport(admin); |
| 3670 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3671 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | return false; |
| 3675 | } |
| 3676 | |
| 3677 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3678 | * Determine whether or not creating a guest user has been disabled for the device |
| 3679 | * |
| 3680 | * @hide |
| 3681 | */ |
| 3682 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3683 | // Currently guest users can always be created if multi-user is enabled |
| 3684 | // TODO introduce a policy for guest user creation |
| 3685 | return false; |
| 3686 | } |
| 3687 | |
| 3688 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3689 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3690 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3691 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3692 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3693 | * <p> |
| 3694 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3695 | * exception will be thrown. |
| 3696 | * <p> |
| 3697 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3698 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3699 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3700 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3701 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3702 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3703 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3704 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3705 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3706 | if (mService != null) { |
| 3707 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3708 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3709 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3710 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3711 | } |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3716 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3717 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3718 | * @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] | 3719 | * have disabled screen capture. |
| 3720 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3721 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3722 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3723 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3727 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3728 | if (mService != null) { |
| 3729 | try { |
| 3730 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3731 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3732 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | return false; |
| 3736 | } |
| 3737 | |
| 3738 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3739 | * Called by a device owner to set whether auto time is required. If auto time is required the |
| 3740 | * user cannot set the date and time, but has to use network date and time. |
| 3741 | * <p> |
| 3742 | * Note: if auto time is required the user can still manually set the time zone. |
| 3743 | * <p> |
| 3744 | * The calling device admin must be a device owner. If it is not, a security exception will be |
| 3745 | * thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3746 | * |
| 3747 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3748 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3749 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3750 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3751 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3752 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3753 | if (mService != null) { |
| 3754 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3755 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3756 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3757 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3758 | } |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | /** |
| 3763 | * @return true if auto time is required. |
| 3764 | */ |
| 3765 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3766 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3767 | if (mService != null) { |
| 3768 | try { |
| 3769 | return mService.getAutoTimeRequired(); |
| 3770 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3771 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3772 | } |
| 3773 | } |
| 3774 | return false; |
| 3775 | } |
| 3776 | |
| 3777 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3778 | * 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] | 3779 | * <p> |
| 3780 | * The system user is exempt from this policy - it is never ephemeral. |
| 3781 | * <p> |
| 3782 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 3783 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3784 | * |
| 3785 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3786 | * @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] | 3787 | * subsequently created users will be ephemeral. |
| 3788 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3789 | * @hide |
| 3790 | */ |
| 3791 | public void setForceEphemeralUsers( |
| 3792 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3793 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3794 | if (mService != null) { |
| 3795 | try { |
| 3796 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3797 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3798 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | /** |
| 3804 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3805 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3806 | * @hide |
| 3807 | */ |
| 3808 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3809 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3810 | if (mService != null) { |
| 3811 | try { |
| 3812 | return mService.getForceEphemeralUsers(admin); |
| 3813 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3814 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | return false; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3821 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3822 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3823 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3824 | * <p> |
| 3825 | * The calling device admin must have requested |
| 3826 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 3827 | * if it has not, a security exception will be thrown. |
| 3828 | * <p> |
| 3829 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 3830 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 3831 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3832 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3833 | * <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] | 3834 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3835 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3836 | * there is one, or the parent user otherwise. |
| 3837 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 3838 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3839 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3840 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3841 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3842 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3843 | * profile. |
| 3844 | * <p> |
| 3845 | * Requests to disable other features on a managed profile will be ignored. |
| 3846 | * <p> |
| 3847 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3848 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3849 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3850 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3851 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3852 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 3853 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 3854 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 3855 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 3856 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 3857 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 3858 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3859 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3860 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3861 | if (mService != null) { |
| 3862 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3863 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3864 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3865 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3871 | * 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] | 3872 | * 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] | 3873 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3874 | * |
| 3875 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3876 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3877 | * restrictions on the parent profile. |
| 3878 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3879 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3880 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3881 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3882 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3883 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3884 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3885 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3889 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3890 | if (mService != null) { |
| 3891 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3892 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3893 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3894 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3895 | } |
| 3896 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3897 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3901 | * @hide |
| 3902 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3903 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3904 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3905 | if (mService != null) { |
| 3906 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3907 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3908 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3909 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3913 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3914 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3915 | * @hide |
| 3916 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3917 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3918 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3922 | * @hide |
| 3923 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3924 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3925 | if (mService != null) { |
| 3926 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3927 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3928 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3929 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3930 | } |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | /** |
| 3935 | * @hide |
| 3936 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 3937 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3938 | if (mService != null) { |
| 3939 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 3940 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3941 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3942 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3943 | } |
| 3944 | } |
| 3945 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3946 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3947 | /** |
| 3948 | * @hide |
| 3949 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 3950 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 3951 | if (mService != null) { |
| 3952 | try { |
| 3953 | mService.reportPasswordChanged(userId); |
| 3954 | } catch (RemoteException e) { |
| 3955 | throw e.rethrowFromSystemServer(); |
| 3956 | } |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | /** |
| 3961 | * @hide |
| 3962 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3963 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3964 | if (mService != null) { |
| 3965 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3966 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3967 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3968 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3969 | } |
| 3970 | } |
| 3971 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3972 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3973 | /** |
| 3974 | * @hide |
| 3975 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3976 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3977 | if (mService != null) { |
| 3978 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3979 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3980 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3981 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3982 | } |
| 3983 | } |
| 3984 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3985 | |
| 3986 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3987 | * @hide |
| 3988 | */ |
| 3989 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3990 | if (mService != null) { |
| 3991 | try { |
| 3992 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3993 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3994 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3995 | } |
| 3996 | } |
| 3997 | } |
| 3998 | |
| 3999 | /** |
| 4000 | * @hide |
| 4001 | */ |
| 4002 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4003 | if (mService != null) { |
| 4004 | try { |
| 4005 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4006 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4007 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4013 | * Should be called when keyguard has been dismissed. |
| 4014 | * @hide |
| 4015 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4016 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4017 | if (mService != null) { |
| 4018 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4019 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4020 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4021 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4022 | } |
| 4023 | } |
| 4024 | } |
| 4025 | |
| 4026 | /** |
| 4027 | * Should be called when keyguard view has been shown to the user. |
| 4028 | * @hide |
| 4029 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4030 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4031 | if (mService != null) { |
| 4032 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4033 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4034 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4035 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4036 | } |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4041 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4042 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4043 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4044 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4045 | * @return whether the package was successfully registered as the device owner. |
| 4046 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4047 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4048 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4049 | public boolean setDeviceOwner(ComponentName who) { |
| 4050 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | /** |
| 4054 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4055 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4056 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4057 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | /** |
| 4061 | * @hide |
| 4062 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4063 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4064 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | /** |
| 4068 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4069 | * Sets the given package as the device owner. The package must already be installed. There |
| 4070 | * must not already be a device owner. |
| 4071 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4072 | * this method. |
| 4073 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4074 | * 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] | 4075 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4076 | * @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] | 4077 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4078 | * @return whether the package was successfully registered as the device owner. |
| 4079 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4080 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4081 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4082 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4083 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4084 | if (mService != null) { |
| 4085 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4086 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4087 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4088 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4089 | } |
| 4090 | } |
| 4091 | return false; |
| 4092 | } |
| 4093 | |
| 4094 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4095 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4096 | * 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] | 4097 | * 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] | 4098 | * package is currently registered as the device owner app, pass in the package name from |
| 4099 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4100 | * 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] | 4101 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4102 | * the setup process. |
| 4103 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4104 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4105 | * @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] | 4106 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4107 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4108 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4109 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4110 | } |
| 4111 | |
| 4112 | /** |
| 4113 | * @return true if a package is registered as device owner, only when it's running on the |
| 4114 | * calling user. |
| 4115 | * |
| 4116 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4117 | * @hide |
| 4118 | */ |
| 4119 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4120 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4121 | } |
| 4122 | |
| 4123 | /** |
| 4124 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4125 | * user. |
| 4126 | * |
| 4127 | * <p>Requires the MANAGE_USERS permission. |
| 4128 | * |
| 4129 | * @hide |
| 4130 | */ |
| 4131 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4132 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4133 | } |
| 4134 | |
| 4135 | /** |
| 4136 | * @return device owner component name, only when it's running on the calling user. |
| 4137 | * |
| 4138 | * @hide |
| 4139 | */ |
| 4140 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4141 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4142 | } |
| 4143 | |
| 4144 | /** |
| 4145 | * @return device owner component name, even if it's running on a different user. |
| 4146 | * |
| 4147 | * <p>Requires the MANAGE_USERS permission. |
| 4148 | * |
| 4149 | * @hide |
| 4150 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4151 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4152 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4153 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4154 | } |
| 4155 | |
| 4156 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4157 | if (packageName == null) { |
| 4158 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4159 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4160 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4161 | if (deviceOwner == null) { |
| 4162 | return false; |
| 4163 | } |
| 4164 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4165 | } |
| 4166 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4167 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4168 | if (mService != null) { |
| 4169 | try { |
| 4170 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4171 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4172 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4173 | } |
| 4174 | } |
| 4175 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4176 | } |
| 4177 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4178 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4179 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4180 | * no device owner. |
| 4181 | * |
| 4182 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4183 | * |
| 4184 | * @hide |
| 4185 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4186 | public int getDeviceOwnerUserId() { |
| 4187 | if (mService != null) { |
| 4188 | try { |
| 4189 | return mService.getDeviceOwnerUserId(); |
| 4190 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4191 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4192 | } |
| 4193 | } |
| 4194 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4198 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4199 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 4200 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4201 | * |
| 4202 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4203 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4204 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4205 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4206 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4207 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4208 | if (mService != null) { |
| 4209 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4210 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4211 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4212 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4213 | } |
| 4214 | } |
| 4215 | } |
| 4216 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4217 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4218 | * Returns the device owner package name, only if it's running on the calling user. |
| 4219 | * |
| 4220 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4221 | * |
| 4222 | * @hide |
| 4223 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4224 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4225 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4226 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4227 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4228 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4232 | * 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] | 4233 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4234 | * @return whether the device is managed by a Device Owner. |
| 4235 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4236 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4237 | * |
| 4238 | * @hide |
| 4239 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4240 | @SystemApi |
| 4241 | @TestApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4242 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4243 | try { |
| 4244 | return mService.hasDeviceOwner(); |
| 4245 | } catch (RemoteException re) { |
| 4246 | throw re.rethrowFromSystemServer(); |
| 4247 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | /** |
| 4251 | * Returns the device owner name. Note this method *will* return the device owner |
| 4252 | * name when it's running on a different user. |
| 4253 | * |
| 4254 | * <p>Requires the MANAGE_USERS permission. |
| 4255 | * |
| 4256 | * @hide |
| 4257 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4258 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4259 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4260 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4261 | if (mService != null) { |
| 4262 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4263 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4264 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4265 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4266 | } |
| 4267 | } |
| 4268 | return null; |
| 4269 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4270 | |
| 4271 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4272 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4273 | * @deprecated Do not use |
| 4274 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4275 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4276 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4277 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4278 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4279 | return null; |
| 4280 | } |
| 4281 | |
| 4282 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4283 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4284 | * @deprecated Do not use |
| 4285 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4286 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4287 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4288 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4289 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4290 | return null; |
| 4291 | } |
| 4292 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4293 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4294 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4295 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4296 | * Sets the given component as an active admin and registers the package as the profile |
| 4297 | * owner for this user. The package must already be installed and there shouldn't be |
| 4298 | * an existing profile owner registered for this user. Also, this method must be called |
| 4299 | * before the user setup has been completed. |
| 4300 | * <p> |
| 4301 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4302 | * MANAGE_DEVICE_ADMINS permission. |
| 4303 | * @param admin The component to register as an active admin and profile owner. |
| 4304 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4305 | * @return whether the admin was successfully registered as the profile owner. |
| 4306 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4307 | * the user has already been set up. |
| 4308 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4309 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4310 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4311 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4312 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4313 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4314 | if (mService != null) { |
| 4315 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4316 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4317 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4318 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4319 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4320 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4321 | } |
| 4322 | } |
| 4323 | return false; |
| 4324 | } |
| 4325 | |
| 4326 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4327 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 4328 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 4329 | * will be thrown. |
| 4330 | * <p> |
| 4331 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4332 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4333 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4334 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4335 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4336 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4337 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4338 | if (mService != null) { |
| 4339 | try { |
| 4340 | mService.clearProfileOwner(admin); |
| 4341 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4342 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4348 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4349 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4350 | */ |
| 4351 | public boolean hasUserSetupCompleted() { |
| 4352 | if (mService != null) { |
| 4353 | try { |
| 4354 | return mService.hasUserSetupCompleted(); |
| 4355 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4356 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4357 | } |
| 4358 | } |
| 4359 | return true; |
| 4360 | } |
| 4361 | |
| 4362 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4363 | * @hide |
| 4364 | * 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] | 4365 | * already be installed. There must not already be a profile owner for this user. |
| 4366 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4367 | * this method. |
| 4368 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4369 | * - the caller is SYSTEM_UID. |
| 4370 | * - 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] | 4371 | * @param admin the component name to be registered as profile owner. |
| 4372 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4373 | * @param userHandle the userId to set the profile owner for. |
| 4374 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4375 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4376 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4377 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4378 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4379 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4380 | if (mService != null) { |
| 4381 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4382 | if (ownerName == null) { |
| 4383 | ownerName = ""; |
| 4384 | } |
| 4385 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4386 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4387 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4388 | } |
| 4389 | } |
| 4390 | return false; |
| 4391 | } |
| 4392 | |
| 4393 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4394 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4395 | * <p> |
| 4396 | * 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] | 4397 | * 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] | 4398 | * <p> |
| 4399 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4400 | * will be blank and the user will not be allowed to change it. |
| 4401 | * <p> |
| 4402 | * 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] | 4403 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4404 | * and set a new version of this string accordingly. |
| 4405 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4406 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4407 | * @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] | 4408 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4409 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4410 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4411 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4412 | if (mService != null) { |
| 4413 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4414 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4415 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4416 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4417 | } |
| 4418 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | /** |
| 4422 | * @return The device owner information. If it is not set returns {@code null}. |
| 4423 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4424 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4425 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4426 | if (mService != null) { |
| 4427 | try { |
| 4428 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4429 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4430 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4431 | } |
| 4432 | } |
| 4433 | return null; |
| 4434 | } |
| 4435 | |
| 4436 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4437 | * Called by device or profile owners to suspend packages for this user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4438 | * <p> |
| 4439 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4440 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4441 | * device. |
| 4442 | * <p> |
| 4443 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4444 | * 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] | 4445 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4446 | * |
| 4447 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4448 | * @param packageNames The package names to suspend or unsuspend. |
| 4449 | * @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] | 4450 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4451 | * @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] | 4452 | * this method. |
| 4453 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4454 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4455 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4456 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4457 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4458 | if (mService != null) { |
| 4459 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4460 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4461 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4462 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4463 | } |
| 4464 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4465 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | /** |
| 4469 | * Called by device or profile owners to determine if a package is suspended. |
| 4470 | * |
| 4471 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4472 | * @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] | 4473 | * @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] | 4474 | * suspended, could not be found or an error occurred. |
| 4475 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4476 | * @throws NameNotFoundException if the package could not be found. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4477 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4478 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4479 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4480 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4481 | if (mService != null) { |
| 4482 | try { |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4483 | return mService.isPackageSuspended(admin, packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4484 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4485 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4486 | } catch (IllegalArgumentException ex) { |
| 4487 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4488 | } |
| 4489 | } |
| 4490 | return false; |
| 4491 | } |
| 4492 | |
| 4493 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4494 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4495 | * be used. Only the profile owner can call this. |
| 4496 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4497 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4498 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4499 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4500 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4501 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4502 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4503 | if (mService != null) { |
| 4504 | try { |
| 4505 | mService.setProfileEnabled(admin); |
| 4506 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4507 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4508 | } |
| 4509 | } |
| 4510 | } |
| 4511 | |
| 4512 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4513 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4514 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4515 | * 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] | 4516 | * |
| 4517 | * @see #isProfileOwnerApp |
| 4518 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4519 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4520 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4521 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4522 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4523 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4524 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4525 | if (mService != null) { |
| 4526 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4527 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4528 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4529 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4530 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4531 | } |
| 4532 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4533 | |
| 4534 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4535 | * 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] | 4536 | * 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] | 4537 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4538 | * |
| 4539 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4540 | * @return Whether or not the package is registered as the profile owner. |
| 4541 | */ |
| 4542 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4543 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4544 | if (mService != null) { |
| 4545 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4546 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4547 | return profileOwner != null |
| 4548 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4549 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4550 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4551 | } |
| 4552 | } |
| 4553 | return false; |
| 4554 | } |
| 4555 | |
| 4556 | /** |
| 4557 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4558 | * @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] | 4559 | * owner has been set for that user. |
| 4560 | * @throws IllegalArgumentException if the userId is invalid. |
| 4561 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4562 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4563 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4564 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4565 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4566 | } |
| 4567 | |
| 4568 | /** |
| 4569 | * @see #getProfileOwner() |
| 4570 | * @hide |
| 4571 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4572 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4573 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4574 | if (mService != null) { |
| 4575 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4576 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4577 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4578 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4579 | } |
| 4580 | } |
| 4581 | return null; |
| 4582 | } |
| 4583 | |
| 4584 | /** |
| 4585 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4586 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4587 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4588 | * @throws IllegalArgumentException if the userId is invalid. |
| 4589 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4590 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4591 | if (mService != null) { |
| 4592 | try { |
| 4593 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4594 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4595 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4596 | } |
| 4597 | } |
| 4598 | return null; |
| 4599 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4600 | |
| 4601 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4602 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4603 | * @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] | 4604 | * @return the human readable name of the organisation associated with this profile owner or |
| 4605 | * null if one is not set. |
| 4606 | * @throws IllegalArgumentException if the userId is invalid. |
| 4607 | */ |
| 4608 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4609 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4610 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4611 | if (mService != null) { |
| 4612 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 4613 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4614 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4615 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4616 | } |
| 4617 | } |
| 4618 | return null; |
| 4619 | } |
| 4620 | |
| 4621 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4622 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 4623 | * 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] | 4624 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 4625 | * intent preferences are reset. |
| 4626 | * <p> |
| 4627 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 4628 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 4629 | * the filter. |
| 4630 | * <p> |
| 4631 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 4632 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4633 | * |
| 4634 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4635 | * @param filter The IntentFilter for which a default handler is added. |
| 4636 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4637 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4638 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4639 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 4640 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4641 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4642 | if (mService != null) { |
| 4643 | try { |
| 4644 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4645 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4646 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4647 | } |
| 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | /** |
| 4652 | * 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] | 4653 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4654 | * <p> |
| 4655 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4656 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4657 | * |
| 4658 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4659 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4660 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4661 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4662 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4663 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4664 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4665 | if (mService != null) { |
| 4666 | try { |
| 4667 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4668 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4669 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4670 | } |
| 4671 | } |
| 4672 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4673 | |
| 4674 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4675 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4676 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4677 | * {@link #getApplicationRestrictions}. |
| 4678 | * <p> |
| 4679 | * This permission is persistent until it is later cleared by calling this method with a |
| 4680 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4681 | * <p> |
| 4682 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4683 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4684 | * |
| 4685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4686 | * @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] | 4687 | * APIs. If {@code null} is given the current package will be cleared. |
| 4688 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4689 | * @throws NameNotFoundException if {@code packageName} is not found |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4690 | */ |
| 4691 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4692 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4693 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4694 | if (mService != null) { |
| 4695 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4696 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4697 | throw new NameNotFoundException(packageName); |
| 4698 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4699 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4700 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4701 | } |
| 4702 | } |
| 4703 | } |
| 4704 | |
| 4705 | /** |
| 4706 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 4707 | * package for the current user, or {@code null} if none is set. |
| 4708 | * |
| 4709 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4710 | * @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] | 4711 | * {@code null} if none is set. |
| 4712 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4713 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4714 | public @Nullable String getApplicationRestrictionsManagingPackage( |
| 4715 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4716 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4717 | if (mService != null) { |
| 4718 | try { |
| 4719 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4720 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4721 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | return null; |
| 4725 | } |
| 4726 | |
| 4727 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4728 | * Called by any application to find out whether it has been granted permission via |
| 4729 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4730 | * for the calling user. |
| 4731 | * |
| 4732 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4733 | * that method. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4734 | */ |
| 4735 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4736 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4737 | if (mService != null) { |
| 4738 | try { |
| 4739 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 4740 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4741 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4742 | } |
| 4743 | } |
| 4744 | return false; |
| 4745 | } |
| 4746 | |
| 4747 | /** |
| 4748 | * 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] | 4749 | * <p> |
| 4750 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4751 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4752 | * security exception will be thrown. |
| 4753 | * <p> |
| 4754 | * 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] | 4755 | * <ul> |
| 4756 | * <li>{@code boolean} |
| 4757 | * <li>{@code int} |
| 4758 | * <li>{@code String} or {@code String[]} |
| 4759 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4760 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4761 | * <p> |
| 4762 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 4763 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4764 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4765 | * <p> |
| 4766 | * The application restrictions are only made visible to the target application via |
| 4767 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 4768 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4769 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4770 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4771 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 4772 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4773 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4774 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4775 | * @param packageName The name of the package to update restricted settings for. |
| 4776 | * @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] | 4777 | * set of active restrictions. |
| 4778 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4779 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4780 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4781 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4782 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4783 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4784 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4785 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4786 | if (mService != null) { |
| 4787 | try { |
| 4788 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 4789 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4790 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4791 | } |
| 4792 | } |
| 4793 | } |
| 4794 | |
| 4795 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4796 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 4797 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 4798 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4799 | * {@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] | 4800 | * <p> |
| 4801 | * The calling device admin must have requested |
| 4802 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4803 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4804 | * <p> |
| 4805 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4806 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 4807 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4808 | * |
| 4809 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4810 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4811 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 4812 | * strictly disabled according to the state of the |
| 4813 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4814 | * <p> |
| 4815 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 4816 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 4817 | * device admins. |
| 4818 | * <p> |
| 4819 | * Consult documentation for the specific TrustAgent to determine legal options |
| 4820 | * parameters. |
| 4821 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4822 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4823 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4824 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4825 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4826 | if (mService != null) { |
| 4827 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4828 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4829 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4830 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4831 | } |
| 4832 | } |
| 4833 | } |
| 4834 | |
| 4835 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4836 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4837 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4838 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4839 | * <p> |
| 4840 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4841 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 4842 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4843 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4844 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4845 | * this function returns a list of configurations for all admins that declare |
| 4846 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4847 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4848 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4849 | * 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] | 4850 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4851 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4852 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4853 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 4854 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4855 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4859 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 4860 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4861 | if (mService != null) { |
| 4862 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4863 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 4864 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4865 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4866 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4867 | } |
| 4868 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4869 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4873 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 4874 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4875 | * <p> |
| 4876 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4877 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4878 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4879 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4880 | * @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] | 4881 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4882 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4883 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4884 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4885 | if (mService != null) { |
| 4886 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4887 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4888 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4889 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4890 | } |
| 4891 | } |
| 4892 | } |
| 4893 | |
| 4894 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4895 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4896 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4897 | * <p> |
| 4898 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4899 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4900 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4901 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4902 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4903 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4904 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4905 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4906 | if (mService != null) { |
| 4907 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4908 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4909 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4910 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4911 | } |
| 4912 | } |
| 4913 | return false; |
| 4914 | } |
| 4915 | |
| 4916 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4917 | * Determine whether or not caller-Id information has been disabled. |
| 4918 | * |
| 4919 | * @param userHandle The user for whom to check the caller-id permission |
| 4920 | * @hide |
| 4921 | */ |
| 4922 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4923 | if (mService != null) { |
| 4924 | try { |
| 4925 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4926 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4927 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4928 | } |
| 4929 | } |
| 4930 | return false; |
| 4931 | } |
| 4932 | |
| 4933 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4934 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 4935 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4936 | * <p> |
| 4937 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4938 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4939 | * |
| 4940 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4941 | * @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] | 4942 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4943 | */ |
| 4944 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4945 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4946 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4947 | if (mService != null) { |
| 4948 | try { |
| 4949 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 4950 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4951 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4952 | } |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | /** |
| 4957 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4958 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4959 | * <p> |
| 4960 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4961 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4962 | * |
| 4963 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4964 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4965 | */ |
| 4966 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4967 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4968 | if (mService != null) { |
| 4969 | try { |
| 4970 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4971 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4972 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4973 | } |
| 4974 | } |
| 4975 | return false; |
| 4976 | } |
| 4977 | |
| 4978 | |
| 4979 | /** |
| 4980 | * Determine whether or not contacts search has been disabled. |
| 4981 | * |
| 4982 | * @param userHandle The user for whom to check the contacts search permission |
| 4983 | * @hide |
| 4984 | */ |
| 4985 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4986 | if (mService != null) { |
| 4987 | try { |
| 4988 | return mService |
| 4989 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4990 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4991 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4992 | } |
| 4993 | } |
| 4994 | return false; |
| 4995 | } |
| 4996 | |
| 4997 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4998 | * 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] | 4999 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5000 | * @hide |
| 5001 | */ |
| 5002 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5003 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5004 | if (mService != null) { |
| 5005 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5006 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5007 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5008 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5009 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5010 | } |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5015 | * 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] | 5016 | * @hide |
| 5017 | */ |
| 5018 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5019 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5020 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5021 | originalIntent); |
| 5022 | } |
| 5023 | |
| 5024 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5025 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5026 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5027 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5028 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5029 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5030 | * <p> |
| 5031 | * This API works on managed profile only. |
| 5032 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5033 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5034 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5035 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5036 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5037 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5038 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5039 | if (mService != null) { |
| 5040 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5041 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5042 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5043 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | } |
| 5047 | |
| 5048 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5049 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5050 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5051 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5052 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5053 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5054 | * <p> |
| 5055 | * This API works on managed profile only. |
| 5056 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5057 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5058 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5059 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5060 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5061 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5062 | if (mService != null) { |
| 5063 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5064 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5065 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5066 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | return true; |
| 5070 | } |
| 5071 | |
| 5072 | /** |
| 5073 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5074 | * <p> |
| 5075 | * This API works on managed profile UserHandle only. |
| 5076 | * |
| 5077 | * @param userHandle The user for whom to check the caller-id permission |
| 5078 | * @hide |
| 5079 | */ |
| 5080 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5081 | if (mService != null) { |
| 5082 | try { |
| 5083 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5084 | .getIdentifier()); |
| 5085 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5086 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5087 | } |
| 5088 | } |
| 5089 | return true; |
| 5090 | } |
| 5091 | |
| 5092 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5093 | * 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] | 5094 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5095 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5096 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5097 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5098 | * @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] | 5099 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5100 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5101 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5102 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5103 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5104 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5105 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5106 | if (mService != null) { |
| 5107 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5108 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5109 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5110 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5111 | } |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5116 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5117 | * 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] | 5118 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5119 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5120 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5121 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5122 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5123 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5124 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5125 | if (mService != null) { |
| 5126 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5127 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5128 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5129 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5130 | } |
| 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5135 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5136 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5137 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5138 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5139 | * the list and not part of the system can not be enabled by the user. |
| 5140 | * <p> |
| 5141 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5142 | * used, calling with an empty list only allows the builtin system's services. |
| 5143 | * <p> |
| 5144 | * 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] | 5145 | * |
| 5146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5147 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5148 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5149 | * accessibility services enabled, that are not in the list. |
| 5150 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5151 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5152 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5153 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5154 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5155 | if (mService != null) { |
| 5156 | try { |
| 5157 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5158 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5159 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5160 | } |
| 5161 | } |
| 5162 | return false; |
| 5163 | } |
| 5164 | |
| 5165 | /** |
| 5166 | * 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] | 5167 | * <p> |
| 5168 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5169 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5170 | * |
| 5171 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5172 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5173 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5174 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5175 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5176 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5177 | if (mService != null) { |
| 5178 | try { |
| 5179 | return mService.getPermittedAccessibilityServices(admin); |
| 5180 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5181 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5182 | } |
| 5183 | } |
| 5184 | return null; |
| 5185 | } |
| 5186 | |
| 5187 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5188 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5189 | * |
| 5190 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5191 | * @param packageName Accessibility service package name that needs to be checked. |
| 5192 | * @param userHandle user id the admin is running as. |
| 5193 | * @return true if the accessibility service is permitted, otherwise false. |
| 5194 | * |
| 5195 | * @hide |
| 5196 | */ |
| 5197 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5198 | @NonNull String packageName, int userHandle) { |
| 5199 | if (mService != null) { |
| 5200 | try { |
| 5201 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5202 | userHandle); |
| 5203 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5204 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5205 | } |
| 5206 | } |
| 5207 | return false; |
| 5208 | } |
| 5209 | |
| 5210 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5211 | * Returns the list of accessibility services permitted by the device or profiles |
| 5212 | * owners of this user. |
| 5213 | * |
| 5214 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5215 | * it will contain the intersection of the permitted lists for any device or profile |
| 5216 | * owners that apply to this user. It will also include any system accessibility services. |
| 5217 | * |
| 5218 | * @param userId which user to check for. |
| 5219 | * @return List of accessiblity service package names. |
| 5220 | * @hide |
| 5221 | */ |
| 5222 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5223 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5224 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5225 | if (mService != null) { |
| 5226 | try { |
| 5227 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5228 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5229 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5230 | } |
| 5231 | } |
| 5232 | return null; |
| 5233 | } |
| 5234 | |
| 5235 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5236 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5237 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5238 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5239 | * When zero or more packages have been added, input method that are not in the list and not |
| 5240 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5241 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5242 | * <p> |
| 5243 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5244 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5245 | * <p> |
| 5246 | * 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] | 5247 | * |
| 5248 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5249 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5250 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5251 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5252 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5253 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5254 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5255 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5256 | if (mService != null) { |
| 5257 | try { |
| 5258 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5259 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5260 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5261 | } |
| 5262 | } |
| 5263 | return false; |
| 5264 | } |
| 5265 | |
| 5266 | |
| 5267 | /** |
| 5268 | * 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] | 5269 | * <p> |
| 5270 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5271 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5272 | * |
| 5273 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5274 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5275 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5276 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5277 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5278 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5279 | if (mService != null) { |
| 5280 | try { |
| 5281 | return mService.getPermittedInputMethods(admin); |
| 5282 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5283 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5284 | } |
| 5285 | } |
| 5286 | return null; |
| 5287 | } |
| 5288 | |
| 5289 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5290 | * Called by the system to check if a specific input method is disabled by admin. |
| 5291 | * |
| 5292 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5293 | * @param packageName Input method package name that needs to be checked. |
| 5294 | * @param userHandle user id the admin is running as. |
| 5295 | * @return true if the input method is permitted, otherwise false. |
| 5296 | * |
| 5297 | * @hide |
| 5298 | */ |
| 5299 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5300 | @NonNull String packageName, int userHandle) { |
| 5301 | if (mService != null) { |
| 5302 | try { |
| 5303 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5304 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5305 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | return false; |
| 5309 | } |
| 5310 | |
| 5311 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5312 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5313 | * 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] | 5314 | * |
| 5315 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5316 | * it will contain the intersection of the permitted lists for any device or profile |
| 5317 | * owners that apply to this user. It will also include any system input methods. |
| 5318 | * |
| 5319 | * @return List of input method package names. |
| 5320 | * @hide |
| 5321 | */ |
| 5322 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5323 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5324 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5325 | if (mService != null) { |
| 5326 | try { |
| 5327 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5328 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5329 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5330 | } |
| 5331 | } |
| 5332 | return null; |
| 5333 | } |
| 5334 | |
| 5335 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5336 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 5337 | * currently installed it. |
| 5338 | * |
| 5339 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5340 | * |
| 5341 | * @return List of package names to keep cached. |
| 5342 | * @hide |
| 5343 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5344 | public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5345 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5346 | if (mService != null) { |
| 5347 | try { |
| 5348 | return mService.getKeepUninstalledPackages(admin); |
| 5349 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5350 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5351 | } |
| 5352 | } |
| 5353 | return null; |
| 5354 | } |
| 5355 | |
| 5356 | /** |
| 5357 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 5358 | * currently installed it. |
| 5359 | * |
| 5360 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5361 | * automatically pre-cached.</p> |
| 5362 | * |
| 5363 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5364 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5365 | * @throws SecurityException if {@code admin} is not a device owner. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5366 | * @hide |
| 5367 | */ |
| 5368 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 5369 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5370 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5371 | if (mService != null) { |
| 5372 | try { |
| 5373 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 5374 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5375 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5376 | } |
| 5377 | } |
| 5378 | } |
| 5379 | |
| 5380 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5381 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5382 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5383 | * created. If you need to persist an identifier for this user, use |
| 5384 | * {@link UserManager#getSerialNumberForUser}. |
| 5385 | * |
| 5386 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5387 | * @param name the user's name |
| 5388 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5389 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5390 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5391 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5392 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5393 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5394 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5395 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5396 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5397 | return null; |
| 5398 | } |
| 5399 | |
| 5400 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5401 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5402 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5403 | * created. If you need to persist an identifier for this user, use |
| 5404 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5405 | * immediately. |
| 5406 | * |
| 5407 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5408 | * as registered as an active admin on the new user. The profile owner package will be |
| 5409 | * installed on the new user if it already is installed on the device. |
| 5410 | * |
| 5411 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5412 | * profileOwnerComponent when onEnable is called. |
| 5413 | * |
| 5414 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5415 | * @param name the user's name |
| 5416 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5417 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5418 | * the user. |
| 5419 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5420 | * on the new user. |
| 5421 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5422 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5423 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5424 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5425 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5426 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5427 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5428 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5429 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5430 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5431 | return null; |
| 5432 | } |
| 5433 | |
| 5434 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5435 | * 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] | 5436 | */ |
| 5437 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5438 | |
| 5439 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5440 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5441 | * ephemeral. |
| 5442 | * @hide |
| 5443 | */ |
| 5444 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5445 | |
| 5446 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5447 | * Called by a device owner to create a user with the specified name and a given component of |
| 5448 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5449 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5450 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5451 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5452 | * <p> |
| 5453 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5454 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5455 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5456 | * on the new user. |
| 5457 | * <p> |
| 5458 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5459 | * 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] | 5460 | * |
| 5461 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5462 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5463 | * @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] | 5464 | * same package as admin, otherwise no user is created and an |
| 5465 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5466 | * @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] | 5467 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5468 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5469 | * @see UserHandle |
| 5470 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5471 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5472 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5473 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5474 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5475 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5476 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5477 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5478 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5479 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5480 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5481 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5482 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5483 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5487 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5488 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5489 | * |
| 5490 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5491 | * @param userHandle the user to remove. |
| 5492 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5493 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5494 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5495 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5496 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5497 | try { |
| 5498 | return mService.removeUser(admin, userHandle); |
| 5499 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5500 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5501 | } |
| 5502 | } |
| 5503 | |
| 5504 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5505 | * Called by a device owner to switch the specified user to the foreground. |
| 5506 | * |
| 5507 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5508 | * @param userHandle the user to switch to; null will switch to primary. |
| 5509 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5510 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5511 | * @see Intent#ACTION_USER_FOREGROUND |
| 5512 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5513 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5514 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5515 | try { |
| 5516 | return mService.switchUser(admin, userHandle); |
| 5517 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5518 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5519 | } |
| 5520 | } |
| 5521 | |
| 5522 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5523 | * Retrieves the application restrictions for a given target application running in the calling |
| 5524 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5525 | * <p> |
| 5526 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 5527 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 5528 | * security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5529 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5530 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5531 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5532 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5533 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5534 | * @param packageName The name of the package to fetch restricted settings of. |
| 5535 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5536 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 5537 | * {@link Bundle} if no restrictions have been set. |
| 5538 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5539 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5540 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5541 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5542 | public @NonNull Bundle getApplicationRestrictions( |
| 5543 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5544 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5545 | if (mService != null) { |
| 5546 | try { |
| 5547 | return mService.getApplicationRestrictions(admin, packageName); |
| 5548 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5549 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5550 | } |
| 5551 | } |
| 5552 | return null; |
| 5553 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5554 | |
| 5555 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5556 | * 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] | 5557 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5558 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5559 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5560 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5561 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5562 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5563 | * for the list of keys. |
| 5564 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5565 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5566 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5567 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5568 | if (mService != null) { |
| 5569 | try { |
| 5570 | mService.setUserRestriction(admin, key, true); |
| 5571 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5572 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5573 | } |
| 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5578 | * 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] | 5579 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5580 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5581 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5582 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5583 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5584 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5585 | * for the list of keys. |
| 5586 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5587 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5588 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5589 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5590 | if (mService != null) { |
| 5591 | try { |
| 5592 | mService.setUserRestriction(admin, key, false); |
| 5593 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5594 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5595 | } |
| 5596 | } |
| 5597 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 5598 | |
| 5599 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5600 | * Called by a profile or device owner to get user restrictions set with |
| 5601 | * {@link #addUserRestriction(ComponentName, String)}. |
| 5602 | * <p> |
| 5603 | * 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] | 5604 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5605 | * {@link UserManager#getUserRestrictions()}. |
| 5606 | * |
| 5607 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5608 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5609 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5610 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5611 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5612 | Bundle ret = null; |
| 5613 | if (mService != null) { |
| 5614 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 5615 | ret = mService.getUserRestrictions(admin); |
| 5616 | } catch (RemoteException e) { |
| 5617 | throw e.rethrowFromSystemServer(); |
| 5618 | } |
| 5619 | } |
| 5620 | return ret == null ? new Bundle() : ret; |
| 5621 | } |
| 5622 | |
| 5623 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5624 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it is |
| 5625 | * unavailable for use, but the data and actual package file remain. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5626 | * |
| 5627 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5628 | * @param packageName The name of the package to hide or unhide. |
| 5629 | * @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] | 5630 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5631 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5632 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5633 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5634 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5635 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5636 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5637 | if (mService != null) { |
| 5638 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5639 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5640 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5641 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5642 | } |
| 5643 | } |
| 5644 | return false; |
| 5645 | } |
| 5646 | |
| 5647 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5648 | * Called by profile or device owners to determine if a package is hidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5649 | * |
| 5650 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5651 | * @param packageName The name of the package to retrieve the hidden status of. |
| 5652 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5653 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5654 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5655 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5656 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5657 | if (mService != null) { |
| 5658 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5659 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5660 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5661 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5662 | } |
| 5663 | } |
| 5664 | return false; |
| 5665 | } |
| 5666 | |
| 5667 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5668 | * Called by profile or device owners to re-enable a system app that was disabled by default |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5669 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5670 | * |
| 5671 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5672 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5673 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5674 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5675 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5676 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5677 | if (mService != null) { |
| 5678 | try { |
| 5679 | mService.enableSystemApp(admin, packageName); |
| 5680 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5681 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5682 | } |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5687 | * Called by profile or device owners to re-enable system apps by intent that were disabled by |
| 5688 | * default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5689 | * |
| 5690 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5691 | * @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] | 5692 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5693 | * @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] | 5694 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5695 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5696 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5697 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5698 | if (mService != null) { |
| 5699 | try { |
| 5700 | return mService.enableSystemAppWithIntent(admin, intent); |
| 5701 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5702 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5703 | } |
| 5704 | } |
| 5705 | return 0; |
| 5706 | } |
| 5707 | |
| 5708 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 5709 | * Called by a device owner or profile owner to disable account management for a specific type |
| 5710 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5711 | * <p> |
| 5712 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 5713 | * exception will be thrown. |
| 5714 | * <p> |
| 5715 | * When account management is disabled for an account type, adding or removing an account of |
| 5716 | * that type will not be possible. |
| 5717 | * <p> |
| 5718 | * 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] | 5719 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 5720 | * management for a specific type is disabled. |
| 5721 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5722 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5723 | * @param accountType For which account management is disabled or enabled. |
| 5724 | * @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] | 5725 | * enabled (false). |
| 5726 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5727 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5728 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5729 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5730 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5731 | if (mService != null) { |
| 5732 | try { |
| 5733 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 5734 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5735 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5736 | } |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5741 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 5742 | * |
| 5743 | * <p> Account management can be disabled/enabled by calling |
| 5744 | * {@link #setAccountManagementDisabled}. |
| 5745 | * |
| 5746 | * @return a list of account types for which account management has been disabled. |
| 5747 | * |
| 5748 | * @see #setAccountManagementDisabled |
| 5749 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5750 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5751 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5752 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | /** |
| 5756 | * @see #getAccountTypesWithManagementDisabled() |
| 5757 | * @hide |
| 5758 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5759 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5760 | if (mService != null) { |
| 5761 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5762 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5763 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5764 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | return null; |
| 5769 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5770 | |
| 5771 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5772 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5773 | * <p> |
| 5774 | * Any packages that shares uid with an allowed package will also be allowed to activate lock |
| 5775 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
| 5776 | * package list results in locked tasks belonging to those packages to be finished. This |
| 5777 | * function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5778 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5779 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5780 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5781 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5782 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 5783 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 5784 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 5785 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5786 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5787 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5788 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5789 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5790 | if (mService != null) { |
| 5791 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5792 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5793 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5794 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5795 | } |
| 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5800 | * This function returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5801 | * |
| 5802 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5803 | * @hide |
| 5804 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5805 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5806 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5807 | if (mService != null) { |
| 5808 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5809 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5810 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5811 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5812 | } |
| 5813 | } |
| 5814 | return null; |
| 5815 | } |
| 5816 | |
| 5817 | /** |
| 5818 | * This function lets the caller know whether the given component is allowed to start the |
| 5819 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5820 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5821 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5822 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5823 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5824 | if (mService != null) { |
| 5825 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5826 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5827 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5828 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5829 | } |
| 5830 | } |
| 5831 | return false; |
| 5832 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5833 | |
| 5834 | /** |
| 5835 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 5836 | * 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] | 5837 | * <p> |
| 5838 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5839 | * <ul> |
| 5840 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 5841 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 5842 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5843 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5844 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5845 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5846 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 5847 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 5848 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 5849 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 5850 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5851 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5852 | * <p> |
| 5853 | * 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] | 5854 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5855 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 5856 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5857 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5858 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5859 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 5860 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5861 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5862 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 5863 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5864 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5865 | * |
| 5866 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5867 | * @param setting The name of the setting to update. |
| 5868 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5869 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5870 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5871 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5872 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5873 | if (mService != null) { |
| 5874 | try { |
| 5875 | mService.setGlobalSetting(admin, setting, value); |
| 5876 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5877 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5878 | } |
| 5879 | } |
| 5880 | } |
| 5881 | |
| 5882 | /** |
| 5883 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5884 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5885 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5886 | * <p> |
| 5887 | * 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] | 5888 | * <ul> |
| 5889 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5890 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5891 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5892 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5893 | * <p> |
| 5894 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5895 | * <ul> |
| 5896 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5897 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5898 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5899 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5900 | * @param setting The name of the setting to update. |
| 5901 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5902 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5903 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5904 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5905 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5906 | if (mService != null) { |
| 5907 | try { |
| 5908 | mService.setSecureSetting(admin, setting, value); |
| 5909 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5910 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5911 | } |
| 5912 | } |
| 5913 | } |
| 5914 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5915 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5916 | * Designates a specific service component as the provider for making permission requests of a |
| 5917 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5918 | * <p/> |
| 5919 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5920 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5921 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5922 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5923 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 5924 | * provider previously assigned. |
| 5925 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5927 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5928 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5929 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5930 | if (mService != null) { |
| 5931 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5932 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5933 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5934 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5935 | } |
| 5936 | } |
| 5937 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5938 | |
| 5939 | /** |
| 5940 | * 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] | 5941 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5942 | * |
| 5943 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5944 | * @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] | 5945 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5946 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5947 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5948 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5949 | if (mService != null) { |
| 5950 | try { |
| 5951 | mService.setMasterVolumeMuted(admin, on); |
| 5952 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5953 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5954 | } |
| 5955 | } |
| 5956 | } |
| 5957 | |
| 5958 | /** |
| 5959 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5960 | * |
| 5961 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5962 | * @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] | 5963 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5964 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5965 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5966 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5967 | if (mService != null) { |
| 5968 | try { |
| 5969 | return mService.isMasterVolumeMuted(admin); |
| 5970 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5971 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5972 | } |
| 5973 | } |
| 5974 | return false; |
| 5975 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5976 | |
| 5977 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5978 | * Called by profile or device owners to change whether a user can uninstall a package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5979 | * |
| 5980 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5981 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5982 | * @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] | 5983 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5984 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5985 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5986 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5987 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5988 | if (mService != null) { |
| 5989 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5990 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5991 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5992 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5993 | } |
| 5994 | } |
| 5995 | } |
| 5996 | |
| 5997 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5998 | * 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] | 5999 | * 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] | 6000 | * <p> |
| 6001 | * <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] | 6002 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6003 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6004 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6005 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6006 | * @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] | 6007 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6008 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6009 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6010 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6011 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6012 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6013 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6014 | if (mService != null) { |
| 6015 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6016 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6017 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6018 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6019 | } |
| 6020 | } |
| 6021 | return false; |
| 6022 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6023 | |
| 6024 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6025 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6026 | * package to be available in the parent profile. As a result the user will be able to add |
| 6027 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6028 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6029 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6030 | * <p> |
| 6031 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6032 | * |
| 6033 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6034 | * @param packageName The package from which widget providers are white-listed. |
| 6035 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6036 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6037 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6038 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6039 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6040 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6041 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6042 | if (mService != null) { |
| 6043 | try { |
| 6044 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6045 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6046 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6047 | } |
| 6048 | } |
| 6049 | return false; |
| 6050 | } |
| 6051 | |
| 6052 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6053 | * 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] | 6054 | * package to be available in the parent profile. For this method to take effect the package |
| 6055 | * should have been added via |
| 6056 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6057 | * <p> |
| 6058 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6059 | * |
| 6060 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6061 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6062 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6063 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6064 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6065 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6066 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6067 | public boolean removeCrossProfileWidgetProvider( |
| 6068 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6069 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6070 | if (mService != null) { |
| 6071 | try { |
| 6072 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6073 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6074 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6075 | } |
| 6076 | } |
| 6077 | return false; |
| 6078 | } |
| 6079 | |
| 6080 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6081 | * 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] | 6082 | * available in the parent profile. |
| 6083 | * |
| 6084 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6085 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6086 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6087 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6088 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6089 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6090 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6091 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6092 | if (mService != null) { |
| 6093 | try { |
| 6094 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6095 | if (providers != null) { |
| 6096 | return providers; |
| 6097 | } |
| 6098 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6099 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6100 | } |
| 6101 | } |
| 6102 | return Collections.emptyList(); |
| 6103 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6104 | |
| 6105 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6106 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6107 | * |
| 6108 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6109 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6110 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6111 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6112 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6113 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6114 | try { |
| 6115 | mService.setUserIcon(admin, icon); |
| 6116 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6117 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6118 | } |
| 6119 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6120 | |
| 6121 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6122 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6123 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6124 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6125 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6126 | * components in the device owner package can set system update policies and the most |
| 6127 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6128 | * @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] | 6129 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6130 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6131 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6132 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6133 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6134 | if (mService != null) { |
| 6135 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6136 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6137 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6138 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6144 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6145 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6146 | * @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] | 6147 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6148 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6149 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6150 | if (mService != null) { |
| 6151 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6152 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6153 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6154 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6155 | } |
| 6156 | } |
| 6157 | return null; |
| 6158 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6159 | |
| 6160 | /** |
| 6161 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6162 | * <p> |
| 6163 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6164 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6165 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6166 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6167 | * |
| 6168 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6169 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6170 | * @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] | 6171 | * place. {@code true} otherwise. |
| 6172 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6173 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6174 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6175 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6176 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6177 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6178 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6179 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6180 | } |
| 6181 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6182 | |
| 6183 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6184 | * 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] | 6185 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6186 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6187 | * |
| 6188 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6189 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6190 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6191 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6192 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6193 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6194 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6195 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6196 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6197 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6198 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6199 | } |
| 6200 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6201 | |
| 6202 | /** |
| 6203 | * Callable by the system update service to notify device owners about pending updates. |
| 6204 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6205 | * permission. |
| 6206 | * |
| 6207 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 6208 | * when the current pending update was first available. -1 if no update is available. |
| 6209 | * @hide |
| 6210 | */ |
| 6211 | @SystemApi |
| 6212 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6213 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6214 | if (mService != null) { |
| 6215 | try { |
| 6216 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 6217 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6218 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6219 | } |
| 6220 | } |
| 6221 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6222 | |
| 6223 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6224 | * Called by profile or device owners to set the default response for future runtime permission |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6225 | * requests by applications. The policy can allow for normal operation which prompts the user to |
| 6226 | * grant a permission, or can allow automatic granting or denying of runtime permission requests |
| 6227 | * by an application. This also applies to new permissions declared by app updates. When a |
| 6228 | * permission is denied or granted this way, the effect is equivalent to setting the permission |
| 6229 | * grant state via {@link #setPermissionGrantState}. |
| 6230 | * <p/> |
| 6231 | * 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] | 6232 | * 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] | 6233 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6234 | * @param admin Which profile or device owner this request is associated with. |
| 6235 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6236 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6237 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6238 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6240 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6241 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6242 | try { |
| 6243 | mService.setPermissionPolicy(admin, policy); |
| 6244 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6245 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | /** |
| 6250 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6251 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 6252 | * @param admin Which profile or device owner this request is associated with. |
| 6253 | * @return the current policy for future permission requests. |
| 6254 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6255 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6256 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6257 | try { |
| 6258 | return mService.getPermissionPolicy(admin); |
| 6259 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6260 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6265 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6266 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6267 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6268 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6269 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6270 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6271 | * by a profile or device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6272 | * <p/> |
| 6273 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6274 | * the permission. It retains the previous grant, if any. |
| 6275 | * <p/> |
| 6276 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6277 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6278 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6279 | * @param admin Which profile or device owner this request is associated with. |
| 6280 | * @param packageName The application to grant or revoke a permission to. |
| 6281 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6282 | * @param grantState The permission grant state which is one of |
| 6283 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6284 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6285 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6286 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6287 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6288 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6289 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6290 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6291 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6292 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6293 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6294 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6295 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6296 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6297 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6298 | } |
| 6299 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6300 | |
| 6301 | /** |
| 6302 | * Returns the current grant state of a runtime permission for a specific application. |
| 6303 | * |
| 6304 | * @param admin Which profile or device owner this request is associated with. |
| 6305 | * @param packageName The application to check the grant state for. |
| 6306 | * @param permission The permission to check for. |
| 6307 | * @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] | 6308 | * has not set a grant state, the return value is |
| 6309 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6310 | * permission is currently granted for the package. |
| 6311 | * <p/> |
| 6312 | * If a grant state was set by the profile or device owner, then the return value will |
| 6313 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6314 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6315 | * currently denied or granted. |
| 6316 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6317 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6318 | * @see PackageManager#checkPermission(String, String) |
| 6319 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6320 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6321 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6322 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6323 | try { |
| 6324 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 6325 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6326 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6327 | } |
| 6328 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6329 | |
| 6330 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6331 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 6332 | * or device, setting itself as the device or profile owner. |
| 6333 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6334 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6335 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6336 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6337 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 6338 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6339 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6340 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6341 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6342 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6343 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6344 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6345 | } |
| 6346 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6347 | |
| 6348 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6349 | * Checks whether it is possible to initiate provisioning a managed device, |
| 6350 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6351 | * |
| 6352 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6353 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 6354 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 6355 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6356 | * @param packageName The package of the component that would be set as device, user, or profile |
| 6357 | * owner. |
| 6358 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6359 | * @hide |
| 6360 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6361 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 6362 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6363 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6364 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6365 | } catch (RemoteException re) { |
| 6366 | throw re.rethrowFromSystemServer(); |
| 6367 | } |
| 6368 | } |
| 6369 | |
| 6370 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6371 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 6372 | * 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] | 6373 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6374 | * @param admin Which profile owner this request is associated with. |
| 6375 | * @return if this user is a managed profile of another user. |
| 6376 | */ |
| 6377 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6378 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6379 | try { |
| 6380 | return mService.isManagedProfile(admin); |
| 6381 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6382 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6383 | } |
| 6384 | } |
| 6385 | |
| 6386 | /** |
| 6387 | * @hide |
| 6388 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 6389 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 6390 | * @param admin Which device owner this request is associated with. |
| 6391 | * @return if this user is a system-only user. |
| 6392 | */ |
| 6393 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 6394 | try { |
| 6395 | return mService.isSystemOnlyUser(admin); |
| 6396 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6397 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6398 | } |
| 6399 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6400 | |
| 6401 | /** |
| 6402 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 6403 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6404 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6405 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 6406 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 6407 | * <p> |
| 6408 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 6409 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6410 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6411 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6412 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6413 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6414 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6415 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6416 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6417 | } |
| 6418 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6419 | |
| 6420 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6421 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 6422 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6423 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6424 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6425 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6426 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6427 | */ |
| 6428 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6429 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6430 | try { |
| 6431 | mService.reboot(admin); |
| 6432 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6433 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6434 | } |
| 6435 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6436 | |
| 6437 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6438 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 6439 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 6440 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 6441 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 6442 | * truncated. |
| 6443 | * <p> |
| 6444 | * 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] | 6445 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6446 | * and set a new version of this string accordingly. |
| 6447 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6448 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6449 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6450 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 6451 | * existing message. |
| 6452 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6453 | */ |
| 6454 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6455 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6456 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6457 | if (mService != null) { |
| 6458 | try { |
| 6459 | mService.setShortSupportMessage(admin, message); |
| 6460 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6461 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6462 | } |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | /** |
| 6467 | * Called by a device admin to get the short support message. |
| 6468 | * |
| 6469 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6470 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 6471 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6472 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6473 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6474 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6475 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6476 | if (mService != null) { |
| 6477 | try { |
| 6478 | return mService.getShortSupportMessage(admin); |
| 6479 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6480 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6481 | } |
| 6482 | } |
| 6483 | return null; |
| 6484 | } |
| 6485 | |
| 6486 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6487 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 6488 | * in the device administators settings screen. |
| 6489 | * <p> |
| 6490 | * 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] | 6491 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6492 | * and set a new version of this string accordingly. |
| 6493 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6494 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6495 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6496 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 6497 | * existing message. |
| 6498 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6499 | */ |
| 6500 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6501 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6502 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6503 | if (mService != null) { |
| 6504 | try { |
| 6505 | mService.setLongSupportMessage(admin, message); |
| 6506 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6507 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6508 | } |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | /** |
| 6513 | * Called by a device admin to get the long support message. |
| 6514 | * |
| 6515 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6516 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 6517 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6518 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6519 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6520 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6521 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6522 | if (mService != null) { |
| 6523 | try { |
| 6524 | return mService.getLongSupportMessage(admin); |
| 6525 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6526 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6527 | } |
| 6528 | } |
| 6529 | return null; |
| 6530 | } |
| 6531 | |
| 6532 | /** |
| 6533 | * Called by the system to get the short support message. |
| 6534 | * |
| 6535 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6536 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6537 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6538 | * |
| 6539 | * @hide |
| 6540 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6541 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6542 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6543 | if (mService != null) { |
| 6544 | try { |
| 6545 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 6546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6547 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6548 | } |
| 6549 | } |
| 6550 | return null; |
| 6551 | } |
| 6552 | |
| 6553 | |
| 6554 | /** |
| 6555 | * Called by the system to get the long support message. |
| 6556 | * |
| 6557 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6558 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6559 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6560 | * |
| 6561 | * @hide |
| 6562 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6563 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 6564 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6565 | if (mService != null) { |
| 6566 | try { |
| 6567 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 6568 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6569 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6570 | } |
| 6571 | } |
| 6572 | return null; |
| 6573 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6574 | |
| 6575 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6576 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 6577 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6578 | * |
| 6579 | * <p>The following methods are supported for the parent instance, all other methods will |
| 6580 | * throw a SecurityException when called on the parent instance: |
| 6581 | * <ul> |
| 6582 | * <li>{@link #getPasswordQuality}</li> |
| 6583 | * <li>{@link #setPasswordQuality}</li> |
| 6584 | * <li>{@link #getPasswordMinimumLength}</li> |
| 6585 | * <li>{@link #setPasswordMinimumLength}</li> |
| 6586 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 6587 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 6588 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 6589 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 6590 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 6591 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 6592 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 6593 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 6594 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 6595 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 6596 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 6597 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 6598 | * <li>{@link #getPasswordHistoryLength}</li> |
| 6599 | * <li>{@link #setPasswordHistoryLength}</li> |
| 6600 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 6601 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 6602 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 6603 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6604 | * <li>{@link #isActivePasswordSufficient}</li> |
| 6605 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 6606 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 6607 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 6608 | * <li>{@link #getMaximumTimeToLock}</li> |
| 6609 | * <li>{@link #setMaximumTimeToLock}</li> |
| 6610 | * <li>{@link #lockNow}</li> |
| 6611 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 6612 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 6613 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 6614 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 6615 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 6616 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6617 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6618 | * |
| 6619 | * @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] | 6620 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6621 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6622 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6623 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6624 | try { |
| 6625 | if (!mService.isManagedProfile(admin)) { |
| 6626 | throw new SecurityException("The current user does not have a parent profile."); |
| 6627 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6628 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6629 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6630 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6631 | } |
| 6632 | } |
| 6633 | |
| 6634 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 6635 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6636 | * |
| 6637 | * <p> Security logs contain various information intended for security auditing purposes. |
| 6638 | * See {@link SecurityEvent} for details. |
| 6639 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 6640 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 6641 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 6642 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 6643 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 6644 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6645 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6646 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6647 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6648 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6649 | * @see #retrieveSecurityLogs |
| 6650 | */ |
| 6651 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6652 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6653 | try { |
| 6654 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 6655 | } catch (RemoteException re) { |
| 6656 | throw re.rethrowFromSystemServer(); |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6661 | * Return whether security logging is enabled or not by the device owner. |
| 6662 | * |
| 6663 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 6664 | * thrown. |
| 6665 | * |
| 6666 | * @param admin Which device owner this request is associated with. |
| 6667 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 6668 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6669 | */ |
| 6670 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6671 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6672 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6673 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6674 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6675 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6676 | } |
| 6677 | } |
| 6678 | |
| 6679 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6680 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 6681 | * this API after device boots. |
| 6682 | * |
| 6683 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 6684 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 6685 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 6686 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 6687 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 6688 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6689 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6690 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6691 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 6692 | * 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^] | 6693 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 6694 | * profile or secondary user that is not affiliated with the device owner user. |
| 6695 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6696 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6697 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6698 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6699 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6700 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6701 | if (list != null) { |
| 6702 | return list.getList(); |
| 6703 | } else { |
| 6704 | // Rate limit exceeded. |
| 6705 | return null; |
| 6706 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6707 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6708 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6709 | } |
| 6710 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6711 | |
| 6712 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6713 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 6714 | * profile. |
| 6715 | * |
| 6716 | * @hide |
| 6717 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6718 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6719 | mContext.checkSelfPermission( |
| 6720 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 6721 | if (!uInfo.isManagedProfile()) { |
| 6722 | throw new SecurityException("The user " + uInfo.id |
| 6723 | + " does not have a parent profile."); |
| 6724 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6725 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6729 | * 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] | 6730 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6731 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 6732 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 6733 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 6734 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 6735 | * |
| 6736 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 6737 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 6738 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6739 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6740 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6741 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 6742 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 6743 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 6744 | * profile or secondary user that is not affiliated with the device owner user. |
| 6745 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6746 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6747 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 6748 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6749 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6750 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6751 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6752 | if (list != null) { |
| 6753 | return list.getList(); |
| 6754 | } else { |
| 6755 | return null; |
| 6756 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6757 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6758 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6759 | } |
| 6760 | } |
| 6761 | |
| 6762 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6763 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 6764 | * 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] | 6765 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6766 | * <p> |
| 6767 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6768 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 6769 | * |
| 6770 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6771 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6772 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6773 | */ |
| 6774 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6775 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6776 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6777 | // always enforce alpha channel to have 100% opacity |
| 6778 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6779 | mService.setOrganizationColor(admin, color); |
| 6780 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6781 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6782 | } |
| 6783 | } |
| 6784 | |
| 6785 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6786 | * @hide |
| 6787 | * |
| 6788 | * Sets the color used for customization. |
| 6789 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6790 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6791 | * @param userId which user to set the color to. |
| 6792 | * @RequiresPermission(allOf = { |
| 6793 | * Manifest.permission.MANAGE_USERS, |
| 6794 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 6795 | */ |
| 6796 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 6797 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6798 | // always enforce alpha channel to have 100% opacity |
| 6799 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6800 | mService.setOrganizationColorForUser(color, userId); |
| 6801 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6802 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6807 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 6808 | * This color is used as background color of the confirm credentials screen for that user. |
| 6809 | * |
| 6810 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6811 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6812 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6813 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6814 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6815 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6816 | try { |
| 6817 | return mService.getOrganizationColor(admin); |
| 6818 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6819 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | /** |
| 6824 | * @hide |
| 6825 | * Retrieve the customization color for a given user. |
| 6826 | * |
| 6827 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6828 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6829 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6830 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6831 | try { |
| 6832 | return mService.getOrganizationColorForUser(userHandle); |
| 6833 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6834 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6835 | } |
| 6836 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6837 | |
| 6838 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 6839 | * 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] | 6840 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6841 | * <p> |
| 6842 | * 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] | 6843 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6844 | * and set a new version of this string accordingly. |
| 6845 | * |
| 6846 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6847 | * @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] | 6848 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6849 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6850 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6851 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6852 | try { |
| 6853 | mService.setOrganizationName(admin, title); |
| 6854 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6855 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6856 | } |
| 6857 | } |
| 6858 | |
| 6859 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6860 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 6861 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6862 | * |
| 6863 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6864 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6865 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6866 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6867 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6868 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6869 | try { |
| 6870 | return mService.getOrganizationName(admin); |
| 6871 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6872 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 6877 | * Called by the system to retrieve the name of the organization managing the device. |
| 6878 | * |
| 6879 | * @return The organization name or {@code null} if none is set. |
| 6880 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 6881 | * MANAGE_USERS permission and is not the system. |
| 6882 | * |
| 6883 | * @hide |
| 6884 | */ |
| 6885 | @SystemApi |
| 6886 | @TestApi |
| 6887 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 6888 | try { |
| 6889 | return mService.getDeviceOwnerOrganizationName(); |
| 6890 | } catch (RemoteException re) { |
| 6891 | throw re.rethrowFromSystemServer(); |
| 6892 | } |
| 6893 | } |
| 6894 | |
| 6895 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6896 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 6897 | * |
| 6898 | * @param userHandle The user id of the user we're interested in. |
| 6899 | * @return The organization name or {@code null} if none is set. |
| 6900 | * |
| 6901 | * @hide |
| 6902 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6903 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6904 | try { |
| 6905 | return mService.getOrganizationNameForUser(userHandle); |
| 6906 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6907 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6912 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 6913 | * return {@link #STATE_USER_UNMANAGED} |
| 6914 | * @hide |
| 6915 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 6916 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6917 | @UserProvisioningState |
| 6918 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6919 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6920 | if (mService != null) { |
| 6921 | try { |
| 6922 | return mService.getUserProvisioningState(); |
| 6923 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6924 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6925 | } |
| 6926 | } |
| 6927 | return STATE_USER_UNMANAGED; |
| 6928 | } |
| 6929 | |
| 6930 | /** |
| 6931 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 6932 | * |
| 6933 | * @param state to store |
| 6934 | * @param userHandle for user |
| 6935 | * @hide |
| 6936 | */ |
| 6937 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 6938 | if (mService != null) { |
| 6939 | try { |
| 6940 | mService.setUserProvisioningState(state, userHandle); |
| 6941 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6942 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6943 | } |
| 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6948 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 6949 | * 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] | 6950 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 6951 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 6952 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 6953 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 6954 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 6955 | * created. |
| 6956 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6957 | * @param admin Which profile or device owner this request is associated with. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6958 | * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored. |
| 6959 | * |
| 6960 | * @throws NullPointerException if {@code ids} is null or contains null elements. |
| 6961 | * @throws IllegalArgumentException if {@code ids} contains an empty string. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6962 | */ |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6963 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6964 | throwIfParentInstance("setAffiliationIds"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6965 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6966 | mService.setAffiliationIds(admin, ids); |
| 6967 | } catch (RemoteException e) { |
| 6968 | throw e.rethrowFromSystemServer(); |
| 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | /** |
| 6973 | * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 6974 | * empty list if none have been set. |
| 6975 | */ |
| 6976 | public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) { |
| 6977 | throwIfParentInstance("getAffiliationIds"); |
| 6978 | try { |
| 6979 | return mService.getAffiliationIds(admin); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6980 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6981 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6982 | } |
| 6983 | } |
| 6984 | |
| 6985 | /** |
| 6986 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6987 | * Returns whether this user/profile is affiliated with the device. |
| 6988 | * <p> |
| 6989 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 6990 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 6991 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6992 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6993 | */ |
| 6994 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6995 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6996 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6997 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6998 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6999 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7000 | } |
| 7001 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7002 | |
| 7003 | /** |
| 7004 | * @hide |
| 7005 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7006 | * to be started |
| 7007 | * @param packageName the package to check for |
| 7008 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7009 | */ |
| 7010 | public boolean isUninstallInQueue(String packageName) { |
| 7011 | try { |
| 7012 | return mService.isUninstallInQueue(packageName); |
| 7013 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7014 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7015 | } |
| 7016 | } |
| 7017 | |
| 7018 | /** |
| 7019 | * @hide |
| 7020 | * @param packageName the package containing active DAs to be uninstalled |
| 7021 | */ |
| 7022 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7023 | try { |
| 7024 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7025 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7026 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7027 | } |
| 7028 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7029 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7030 | /** |
| 7031 | * @hide |
| 7032 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7033 | * If the admin is a profile owner or device owner it will still be removed. |
| 7034 | * |
| 7035 | * @param userHandle user id to remove the admin for. |
| 7036 | * @param admin The administration compononent to remove. |
| 7037 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7038 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7039 | */ |
| 7040 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7041 | try { |
| 7042 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7043 | } catch (RemoteException re) { |
| 7044 | throw re.rethrowFromSystemServer(); |
| 7045 | } |
| 7046 | } |
| 7047 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7048 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7049 | * Returns whether the device has been provisioned. |
| 7050 | * |
| 7051 | * <p>Not for use by third-party applications. |
| 7052 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7053 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7054 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7055 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7056 | public boolean isDeviceProvisioned() { |
| 7057 | try { |
| 7058 | return mService.isDeviceProvisioned(); |
| 7059 | } catch (RemoteException re) { |
| 7060 | throw re.rethrowFromSystemServer(); |
| 7061 | } |
| 7062 | } |
| 7063 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7064 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7065 | * Writes that the provisioning configuration has been applied. |
| 7066 | * |
| 7067 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7068 | * permission. |
| 7069 | * |
| 7070 | * <p>Not for use by third-party applications. |
| 7071 | * |
| 7072 | * @hide |
| 7073 | */ |
| 7074 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7075 | public void setDeviceProvisioningConfigApplied() { |
| 7076 | try { |
| 7077 | mService.setDeviceProvisioningConfigApplied(); |
| 7078 | } catch (RemoteException re) { |
| 7079 | throw re.rethrowFromSystemServer(); |
| 7080 | } |
| 7081 | } |
| 7082 | |
| 7083 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7084 | * Returns whether the provisioning configuration has been applied. |
| 7085 | * |
| 7086 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7087 | * |
| 7088 | * <p>Not for use by third-party applications. |
| 7089 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7090 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7091 | * |
| 7092 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7093 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7094 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7095 | public boolean isDeviceProvisioningConfigApplied() { |
| 7096 | try { |
| 7097 | return mService.isDeviceProvisioningConfigApplied(); |
| 7098 | } catch (RemoteException re) { |
| 7099 | throw re.rethrowFromSystemServer(); |
| 7100 | } |
| 7101 | } |
| 7102 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7103 | /** |
| 7104 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7105 | * Force update user setup completed status. This API has no effect on user build. |
| 7106 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7107 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7108 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7109 | */ |
| 7110 | public void forceUpdateUserSetupComplete() { |
| 7111 | try { |
| 7112 | mService.forceUpdateUserSetupComplete(); |
| 7113 | } catch (RemoteException re) { |
| 7114 | throw re.rethrowFromSystemServer(); |
| 7115 | } |
| 7116 | } |
| 7117 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7118 | private void throwIfParentInstance(String functionName) { |
| 7119 | if (mParentInstance) { |
| 7120 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7121 | } |
| 7122 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7123 | |
| 7124 | /** |
| 7125 | * @hide |
| 7126 | * Enable backup service. |
| 7127 | * <p>This includes all backup and restore mechanisms. |
| 7128 | * Setting this to {@code false} will make backup service no-op or return empty results. |
| 7129 | * |
| 7130 | * <p>There must be only one user on the device, managed by the device owner. |
| 7131 | * Otherwise a {@link SecurityException} will be thrown. |
| 7132 | * |
| 7133 | * <p>Backup service is off by default when device owner is present. |
| 7134 | */ |
| 7135 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7136 | try { |
| 7137 | mService.setBackupServiceEnabled(admin, enabled); |
| 7138 | } catch (RemoteException re) { |
| 7139 | throw re.rethrowFromSystemServer(); |
| 7140 | } |
| 7141 | } |
| 7142 | |
| 7143 | /** |
| 7144 | * @hide |
| 7145 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
| 7146 | */ |
| 7147 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
| 7148 | try { |
| 7149 | return mService.isBackupServiceEnabled(admin); |
| 7150 | } catch (RemoteException re) { |
| 7151 | throw re.rethrowFromSystemServer(); |
| 7152 | } |
| 7153 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7154 | |
| 7155 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 7156 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7157 | * |
| 7158 | * <p> Network logs contain DNS lookup and connect() library call events. |
| 7159 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 7160 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7161 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7162 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7163 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7164 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7165 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7166 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7167 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 7168 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7169 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7170 | */ |
| 7171 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7172 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7173 | try { |
| 7174 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7175 | } catch (RemoteException re) { |
| 7176 | throw re.rethrowFromSystemServer(); |
| 7177 | } |
| 7178 | } |
| 7179 | |
| 7180 | /** |
| 7181 | * Return whether network logging is enabled by a device owner. |
| 7182 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7183 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7184 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7185 | * @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^] | 7186 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7187 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7188 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7189 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7190 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7191 | try { |
| 7192 | return mService.isNetworkLoggingEnabled(admin); |
| 7193 | } catch (RemoteException re) { |
| 7194 | throw re.rethrowFromSystemServer(); |
| 7195 | } |
| 7196 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7197 | |
| 7198 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7199 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7200 | * A device owner has to provide a batchToken provided as part of |
| 7201 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7202 | * token of the most recent available batch of logs, {@code null} will be returned. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7203 | * |
| 7204 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7205 | * |
| 7206 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7207 | * |
| 7208 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7209 | * after the device device owner has been notified via |
| 7210 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7211 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 7212 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7213 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7214 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7215 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7216 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7217 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7218 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7219 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7220 | * @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] | 7221 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7222 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame^] | 7223 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7224 | * 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] | 7225 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7226 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7227 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7228 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7229 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7230 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7231 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7232 | } catch (RemoteException re) { |
| 7233 | throw re.rethrowFromSystemServer(); |
| 7234 | } |
| 7235 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7236 | |
| 7237 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7238 | * Called by a device owner to bind to a service from a profile owner of a managed profile or |
| 7239 | * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
| 7240 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7241 | * <p> |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7242 | * The service must be unexported. Note that the {@link Context} used to obtain this |
| 7243 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7244 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7245 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7246 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7247 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7248 | * explicit component name or a package name to match an |
| 7249 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7250 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7251 | * 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] | 7252 | * @param flags Operation options for the binding operation. See |
| 7253 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7254 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7255 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7256 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7257 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7258 | * {@code false} is returned if the connection is not made and you will not |
| 7259 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7260 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7261 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7262 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7263 | */ |
| 7264 | public boolean bindDeviceAdminServiceAsUser( |
| 7265 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7266 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7267 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7268 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7269 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7270 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 7271 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7272 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7273 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7274 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7275 | sd, flags, targetUser.getIdentifier()); |
| 7276 | } catch (RemoteException re) { |
| 7277 | throw re.rethrowFromSystemServer(); |
| 7278 | } |
| 7279 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7280 | |
| 7281 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7282 | * Returns the list of target users that the calling device or profile owner can use when |
| 7283 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 7284 | * <p> |
| 7285 | * A device owner can bind to a service from a profile owner of a managed profile and |
| 7286 | * vice versa, provided that: |
| 7287 | * <ul> |
| 7288 | * <li>Both belong to the same package name. |
| 7289 | * <li>The managed profile is a profile of the user where the device owner is set. |
| 7290 | * See {@link UserManager#getUserProfiles()} |
| 7291 | * <li>Both users are affiliated. |
Nicolas Prevot | d5b0360 | 2016-12-06 13:32:22 +0000 | [diff] [blame] | 7292 | * See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7293 | * </ul> |
| 7294 | */ |
| 7295 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 7296 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 7297 | try { |
| 7298 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 7299 | } catch (RemoteException re) { |
| 7300 | throw re.rethrowFromSystemServer(); |
| 7301 | } |
| 7302 | } |
| 7303 | |
| 7304 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7305 | * Called by the system to get the time at which the device owner last retrieved security |
| 7306 | * logging entries. |
| 7307 | * |
| 7308 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 7309 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7310 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7311 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7312 | * |
| 7313 | * @hide |
| 7314 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7315 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7316 | public long getLastSecurityLogRetrievalTime() { |
| 7317 | try { |
| 7318 | return mService.getLastSecurityLogRetrievalTime(); |
| 7319 | } catch (RemoteException re) { |
| 7320 | throw re.rethrowFromSystemServer(); |
| 7321 | } |
| 7322 | } |
| 7323 | |
| 7324 | /** |
| 7325 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 7326 | * |
| 7327 | * @return the time at which the device owner most recently requested a bug report, in |
| 7328 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7329 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7330 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7331 | * |
| 7332 | * @hide |
| 7333 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7334 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7335 | public long getLastBugReportRequestTime() { |
| 7336 | try { |
| 7337 | return mService.getLastBugReportRequestTime(); |
| 7338 | } catch (RemoteException re) { |
| 7339 | throw re.rethrowFromSystemServer(); |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | /** |
| 7344 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 7345 | * events. |
| 7346 | * |
| 7347 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 7348 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7349 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7350 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7351 | * |
| 7352 | * @hide |
| 7353 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7354 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7355 | public long getLastNetworkLogRetrievalTime() { |
| 7356 | try { |
| 7357 | return mService.getLastNetworkLogRetrievalTime(); |
| 7358 | } catch (RemoteException re) { |
| 7359 | throw re.rethrowFromSystemServer(); |
| 7360 | } |
| 7361 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 7362 | } |