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 | |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 19 | import android.annotation.CallbackExecutor; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 20 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 22 | import android.annotation.NonNull; |
| 23 | import android.annotation.Nullable; |
Jeff Sharkey | 98af2e4 | 2018-02-16 10:14:57 -0700 | [diff] [blame] | 24 | import android.annotation.RequiresFeature; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 25 | import android.annotation.RequiresPermission; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 26 | import android.annotation.SdkConstant; |
| 27 | import android.annotation.SdkConstant.SdkConstantType; |
yuemingw | 93ffce6 | 2018-02-21 16:20:14 +0000 | [diff] [blame] | 28 | import android.annotation.StringDef; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 29 | import android.annotation.SuppressLint; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 30 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 31 | import android.annotation.SystemService; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 32 | import android.annotation.TestApi; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 33 | import android.annotation.UnsupportedAppUsage; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 34 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 35 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 36 | import android.app.Activity; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 37 | import android.app.IServiceConnection; |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 38 | import android.app.KeyguardManager; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 39 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 40 | import android.content.ComponentName; |
| 41 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 42 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 43 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 44 | import android.content.ServiceConnection; |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 45 | import android.content.pm.ApplicationInfo; |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 46 | import android.content.pm.IPackageDataObserver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 47 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 48 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 49 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 50 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 51 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 52 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 53 | import android.net.Uri; |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 54 | import android.os.Build; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 55 | import android.os.Bundle; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 56 | import android.os.Parcelable; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 57 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 58 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 59 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 60 | import android.os.RemoteException; |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 61 | import android.os.ServiceSpecificException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 62 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 63 | import android.os.UserManager; |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 64 | import android.os.UserManager.UserOperationException; |
| 65 | import android.os.UserManager.UserOperationResult; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 66 | import android.provider.ContactsContract.Directory; |
yuemingw | 93ffce6 | 2018-02-21 16:20:14 +0000 | [diff] [blame] | 67 | import android.provider.Settings; |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 68 | import android.security.AttestedKeyPair; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 69 | import android.security.Credentials; |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 70 | import android.security.KeyChain; |
| 71 | import android.security.KeyChainException; |
Eran Messeri | a173064 | 2017-12-11 17:48:47 +0000 | [diff] [blame] | 72 | import android.security.keymaster.KeymasterCertificateChain; |
| 73 | import android.security.keystore.AttestationUtils; |
| 74 | import android.security.keystore.KeyAttestationException; |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 75 | import android.security.keystore.KeyGenParameterSpec; |
| 76 | import android.security.keystore.ParcelableKeyGenParameterSpec; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 77 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 78 | import android.telephony.TelephonyManager; |
yuemingw | e3d9c09 | 2018-01-11 12:11:44 +0000 | [diff] [blame] | 79 | import android.telephony.data.ApnSetting; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 80 | import android.util.ArraySet; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 81 | import android.util.Log; |
| 82 | |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 83 | import com.android.internal.R; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 84 | import com.android.internal.annotations.VisibleForTesting; |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 85 | import com.android.internal.util.Preconditions; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 86 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 87 | |
| 88 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 89 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 90 | import java.lang.annotation.Retention; |
| 91 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 92 | import java.net.InetSocketAddress; |
| 93 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 94 | import java.security.KeyFactory; |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 95 | import java.security.KeyPair; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 96 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 97 | import java.security.PrivateKey; |
| 98 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 99 | import java.security.cert.CertificateException; |
| 100 | import java.security.cert.CertificateFactory; |
| 101 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 102 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 103 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 104 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 105 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 106 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 107 | import java.util.List; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 108 | import java.util.Set; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 109 | import java.util.concurrent.Executor; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 110 | |
| 111 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 112 | * 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] | 113 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 114 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 115 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 116 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 117 | * application calling an api may only pass as an argument a device administrator component it |
| 118 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 119 | * <div class="special reference"> |
| 120 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 121 | * <p> |
| 122 | * For more information about managing policies for device administration, read the <a href= |
| 123 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 124 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 125 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 126 | @SystemService(Context.DEVICE_POLICY_SERVICE) |
Jeff Sharkey | 98af2e4 | 2018-02-16 10:14:57 -0700 | [diff] [blame] | 127 | @RequiresFeature(PackageManager.FEATURE_DEVICE_ADMIN) |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 128 | public class DevicePolicyManager { |
Eran Messeri | f15d4f4 | 2018-03-23 13:32:17 +0000 | [diff] [blame] | 129 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 130 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 131 | |
| 132 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 133 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 134 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 135 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 136 | /** @hide */ |
| 137 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 138 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 141 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 142 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 143 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 144 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 145 | mContext = context; |
| 146 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 147 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 150 | /** @hide test will override it. */ |
| 151 | @VisibleForTesting |
| 152 | protected int myUserId() { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 153 | return mContext.getUserId(); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 156 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 157 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 158 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 159 | * <p>A managed profile allows data separation for example for the usage of a |
| 160 | * device as a personal and corporate device. The user which provisioning is started from and |
| 161 | * the managed profile share a launcher. |
| 162 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 163 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 164 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 165 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 166 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 167 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 168 | * {@link #isProvisioningAllowed(String)}. |
| 169 | * |
| 170 | * <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] | 171 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 172 | * 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] | 173 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 174 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 175 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 176 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 177 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 178 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 179 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 180 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 181 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 182 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 183 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 184 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 185 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 186 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 187 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 188 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 189 | * <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] | 190 | * in the provisioning intent. The |
| 191 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 192 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 193 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 194 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 195 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 196 | * completed, along with the above broadcast, activity intent |
Esteban Talavera | 4047bae | 2017-06-28 11:03:09 +0100 | [diff] [blame] | 197 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner. |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 198 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 199 | * <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] | 200 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 201 | * |
| 202 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 203 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 204 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 205 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 206 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 207 | */ |
| 208 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 209 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 210 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 211 | |
| 212 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 213 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 214 | * |
| 215 | * <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] | 216 | * 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] | 217 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 218 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 219 | * allowed. |
| 220 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 221 | * <p>The intent contains the following extras: |
| 222 | * <ul> |
| 223 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 224 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 225 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 226 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 227 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 228 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 229 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 230 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 231 | * |
| 232 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 233 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 234 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 235 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 236 | * 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] | 237 | * |
| 238 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 239 | */ |
| 240 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 241 | public static final String ACTION_PROVISION_MANAGED_USER |
| 242 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 243 | |
| 244 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 245 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 246 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 247 | * |
| 248 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 249 | * A device owner has full control over the device. The device owner can not be modified by the |
| 250 | * user. |
| 251 | * |
| 252 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 253 | * employee or client. |
| 254 | * |
| 255 | * <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] | 256 | * It is possible to check if provisioning is allowed or not by querying the method |
| 257 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 258 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 259 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 260 | * <ul> |
| 261 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 262 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 264 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 265 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 266 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 267 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 268 | * </ul> |
| 269 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 270 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 271 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 272 | * device owner. |
| 273 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 274 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 275 | * completed, along with the above broadcast, activity intent |
| 276 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 277 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 278 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 279 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 280 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 281 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 282 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 283 | * 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] | 284 | */ |
| 285 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 286 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 287 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 288 | |
| 289 | /** |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 290 | * Activity action: launch when user provisioning completed, i.e. |
| 291 | * {@link #getUserProvisioningState()} returns one of the complete state. |
| 292 | * |
| 293 | * <p> Please note that the API behavior is not necessarily consistent across various releases, |
| 294 | * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default |
| 295 | * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only. |
| 296 | * |
| 297 | * <p> The activity must be protected by permission |
| 298 | * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold |
| 299 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched. |
| 300 | * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the |
| 301 | * components are not started by this intent. |
| 302 | * @hide |
| 303 | */ |
| 304 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
Jeff Sharkey | 9039636 | 2017-06-12 16:26:53 -0600 | [diff] [blame] | 305 | @SystemApi |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 306 | public static final String ACTION_STATE_USER_SETUP_COMPLETE = |
| 307 | "android.app.action.STATE_USER_SETUP_COMPLETE"; |
| 308 | |
| 309 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 310 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 311 | * |
| 312 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 313 | * the device. A device owner has full control over the device. The device owner can not be |
| 314 | * modified by the user and the only way of resetting the device is via factory reset. |
| 315 | * |
| 316 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 317 | * employee or client. |
| 318 | * |
| 319 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 320 | * |
| 321 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 322 | * by a privileged app with the permission |
| 323 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 324 | * |
| 325 | * <p>The provisioning intent contains the following properties: |
| 326 | * <ul> |
| 327 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 328 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 329 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 330 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 331 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 332 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 333 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 334 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 335 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 336 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 337 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 338 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 339 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 340 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 341 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 342 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 343 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 344 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 345 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Alex Chau | eca99a0 | 2018-04-30 17:51:56 +0100 | [diff] [blame] | 346 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 347 | * <li>{@link #EXTRA_PROVISIONING_USE_MOBILE_DATA, optional </li><ul> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 348 | * |
| 349 | * @hide |
| 350 | */ |
| 351 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 352 | @SystemApi |
| 353 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 354 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 355 | |
| 356 | /** |
| 357 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 358 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 359 | * |
| 360 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 361 | * management state that is distinct from that reached by |
| 362 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 363 | * user, and only has control over device-wide policies, not individual users and their data. |
| 364 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 365 | * this form of device management. |
| 366 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 367 | * <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] | 368 | * A device owner has full control over the device. The device owner can not be modified by the |
| 369 | * user. |
| 370 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 371 | * <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] | 372 | * employee or client. |
| 373 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 374 | * <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] | 375 | * It is possible to check if provisioning is allowed or not by querying the method |
| 376 | * {@link #isProvisioningAllowed(String)}. |
| 377 | * |
| 378 | * <p>The intent contains the following extras: |
| 379 | * <ul> |
| 380 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 381 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 382 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 383 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 384 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 385 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 386 | * </ul> |
| 387 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 388 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 389 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 390 | * device owner. |
| 391 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 392 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 393 | * completed, along with the above broadcast, activity intent |
| 394 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 395 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 396 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 397 | * |
| 398 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 399 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 400 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 401 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 402 | * |
| 403 | * @hide |
| 404 | */ |
| 405 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 406 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 407 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 408 | |
| 409 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 410 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 411 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 412 | * <ul> |
| 413 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 414 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 415 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 416 | * </ul> |
| 417 | * |
| 418 | * @hide |
| 419 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 420 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 421 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 422 | public static final String ACTION_PROVISION_FINALIZATION |
| 423 | = "android.app.action.PROVISION_FINALIZATION"; |
| 424 | |
| 425 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 426 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 427 | * |
| 428 | * @hide |
| 429 | */ |
| 430 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 431 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 432 | |
| 433 | /** |
| 434 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 435 | * |
| 436 | * @hide |
| 437 | */ |
| 438 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 439 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 440 | |
| 441 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 442 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 443 | * |
| 444 | * @hide |
| 445 | */ |
| 446 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 447 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 448 | |
| 449 | /** |
| 450 | * Extra for shared bugreport's SHA-256 hash. |
| 451 | * |
| 452 | * @hide |
| 453 | */ |
| 454 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 455 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 456 | |
| 457 | /** |
| 458 | * Extra for remote bugreport notification shown type. |
| 459 | * |
| 460 | * @hide |
| 461 | */ |
| 462 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 463 | "android.app.extra.bugreport_notification_type"; |
| 464 | |
| 465 | /** |
| 466 | * Notification type for a started remote bugreport flow. |
| 467 | * |
| 468 | * @hide |
| 469 | */ |
| 470 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 471 | |
| 472 | /** |
| 473 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 474 | * being taken. |
| 475 | * |
| 476 | * @hide |
| 477 | */ |
| 478 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 479 | |
| 480 | /** |
| 481 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 482 | * |
| 483 | * @hide |
| 484 | */ |
| 485 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 486 | |
| 487 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 488 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 489 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 490 | * |
| 491 | * @hide |
| 492 | */ |
| 493 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 494 | |
| 495 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 496 | * 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] | 497 | * allows a mobile device management application or NFC programmer application which starts |
| 498 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 499 | * <p> |
| 500 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 501 | * sends the intent to pass data to itself on the newly created profile. |
| 502 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 503 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 504 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 505 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 506 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 507 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 508 | * management application after provisioning. |
| 509 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 510 | * <p> |
| 511 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 512 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 513 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 514 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 515 | */ |
| 516 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 517 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 518 | |
| 519 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 520 | * A String extra holding the package name of the mobile device management application that |
| 521 | * will be set as the profile owner or device owner. |
| 522 | * |
| 523 | * <p>If an application starts provisioning directly via an intent with action |
| 524 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 525 | * application that started provisioning. The package will be set as profile owner in that case. |
| 526 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 527 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 528 | * 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] | 529 | * |
| 530 | * <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] | 531 | * 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] | 532 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 533 | * @see DeviceAdminReceiver |
| 534 | * @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] | 535 | * supported, but only if there is only one device admin receiver in the package that requires |
| 536 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 537 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 538 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 539 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 540 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 541 | |
| 542 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 543 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 544 | * application that will be set as the profile owner or device owner and active admin. |
| 545 | * |
| 546 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 547 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 548 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 549 | * 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] | 550 | * |
| 551 | * <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] | 552 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 553 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 554 | * {@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] | 555 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 556 | * |
| 557 | * @see DeviceAdminReceiver |
| 558 | */ |
| 559 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 560 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 561 | |
| 562 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 563 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 564 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 565 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 566 | * |
| 567 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 568 | */ |
| 569 | |
| 570 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 571 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 572 | |
| 573 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 574 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 575 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 576 | * the account will not be removed from the primary user after it is migrated to the newly |
| 577 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 578 | * |
| 579 | * <p> Defaults to {@code false} |
| 580 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 581 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 582 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 583 | */ |
| 584 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 585 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 586 | |
| 587 | /** |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 588 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the |
| 589 | * device. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 590 | */ |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 591 | @Deprecated |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 592 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 593 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 594 | |
| 595 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 596 | * A integer extra indicating the predominant color to show during the provisioning. |
| 597 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 598 | * |
| 599 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 600 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 601 | */ |
| 602 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 603 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 604 | |
| 605 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 606 | * 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] | 607 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 608 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 609 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 610 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 611 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 612 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 613 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 614 | |
| 615 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 616 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 617 | * will be set to. |
| 618 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 619 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 620 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 621 | */ |
| 622 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 623 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 624 | |
| 625 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 626 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 627 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 628 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 629 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 630 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 631 | */ |
| 632 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 633 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 634 | |
| 635 | /** |
| 636 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 637 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 638 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 639 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 640 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 641 | */ |
| 642 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 643 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 644 | |
| 645 | /** |
| 646 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 647 | * owner provisioning for downloading the mobile device management application. |
| 648 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 649 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 650 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 651 | */ |
| 652 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 653 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 654 | |
| 655 | /** |
| 656 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 657 | * is hidden or not. |
| 658 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 659 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 660 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 661 | */ |
| 662 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 663 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 664 | |
| 665 | /** |
| 666 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 667 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 668 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 669 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 670 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 671 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 672 | */ |
| 673 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 674 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 675 | |
| 676 | /** |
| 677 | * A String extra holding the password of the wifi network in |
| 678 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 679 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 680 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 681 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 682 | */ |
| 683 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 684 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 685 | |
| 686 | /** |
| 687 | * A String extra holding the proxy host for the wifi network in |
| 688 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 689 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 690 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 691 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 692 | */ |
| 693 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 694 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 695 | |
| 696 | /** |
| 697 | * An int extra holding the proxy port for the wifi network in |
| 698 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 699 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 700 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 701 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 702 | */ |
| 703 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 704 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 705 | |
| 706 | /** |
| 707 | * A String extra holding the proxy bypass for the wifi network in |
| 708 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 709 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 710 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 711 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 712 | */ |
| 713 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 714 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 715 | |
| 716 | /** |
| 717 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 718 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 719 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 720 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 721 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 722 | */ |
| 723 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 724 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 725 | |
| 726 | /** |
| 727 | * A String extra holding a url that specifies the download location of the device admin |
| 728 | * package. When not provided it is assumed that the device admin package is already installed. |
| 729 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 730 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 731 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 732 | */ |
| 733 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 734 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 735 | |
| 736 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 737 | * A String extra holding the localized name of the organization under management. |
| 738 | * |
| 739 | * The name is displayed only during provisioning. |
| 740 | * |
| 741 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 742 | * |
| 743 | * @hide |
| 744 | */ |
| 745 | @SystemApi |
| 746 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 747 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 748 | |
| 749 | /** |
Alejandro Fernández | bfd6193 | 2017-04-04 19:33:01 +0100 | [diff] [blame] | 750 | * A String extra holding a url to the website of the device provider so the user can open it |
| 751 | * during provisioning. If the url is not HTTPS, an error will be shown. |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 752 | * |
| 753 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 754 | * |
| 755 | * @hide |
| 756 | */ |
| 757 | @SystemApi |
| 758 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 759 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 760 | |
| 761 | /** |
| 762 | * A String extra holding the localized name of the device admin package. It should be the same |
| 763 | * as the app label of the package. |
| 764 | * |
| 765 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 766 | * |
| 767 | * @hide |
| 768 | */ |
| 769 | @SystemApi |
| 770 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 771 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 772 | |
| 773 | /** |
| 774 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 775 | * shown during the provisioning. |
| 776 | * <h5>The following URI schemes are accepted:</h5> |
| 777 | * <ul> |
| 778 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 779 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 780 | * </ul> |
| 781 | * |
| 782 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 783 | * pixel density for the device. |
| 784 | * |
| 785 | * <p> If a content: URI is passed, the intent should have the flag |
| 786 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 787 | * {@link android.content.ClipData} of the intent too. |
| 788 | * |
| 789 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 790 | * |
| 791 | * @hide |
| 792 | */ |
| 793 | @SystemApi |
| 794 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 795 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 796 | |
| 797 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 798 | * An int extra holding a minimum required version code for the device admin package. If the |
| 799 | * device admin is already installed on the device, it will only be re-downloaded from |
| 800 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 801 | * installed package is less than this version code. |
| 802 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 803 | * <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] | 804 | * provisioning via an NFC bump. |
| 805 | */ |
| 806 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 807 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 808 | |
| 809 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 810 | * A String extra holding a http cookie header which should be used in the http request to the |
| 811 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 812 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 813 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 814 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 815 | */ |
| 816 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 817 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 818 | |
| 819 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 820 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 821 | * the file at download location specified in |
| 822 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 823 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 824 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 825 | * 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] | 826 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 827 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 828 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 829 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 830 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 831 | * |
| 832 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 833 | * 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] | 834 | * 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] | 835 | * 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] | 836 | */ |
| 837 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 838 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 839 | |
| 840 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 841 | * 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] | 842 | * android package archive at the download location specified in {@link |
| 843 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 844 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 845 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 846 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 847 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 848 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 849 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 850 | * 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] | 851 | * the download location. If the checksum does not match an error will be shown to the user and |
| 852 | * the user will be asked to factory reset the device. |
| 853 | * |
| 854 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 855 | * provisioning via an NFC bump. |
| 856 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 857 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 858 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 859 | |
| 860 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 861 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 862 | * has completed successfully. |
| 863 | * |
| 864 | * <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] | 865 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 866 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 867 | * <p>This intent will contain the following extras |
| 868 | * <ul> |
| 869 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 870 | * profile.</li> |
| 871 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 872 | * be migrated at provisioning time, if any.</li> |
| 873 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 874 | */ |
| 875 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 876 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 877 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 878 | |
| 879 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 880 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 881 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 882 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 883 | * delivered faster as it's an activity intent. |
| 884 | * |
Esteban Talavera | 4047bae | 2017-06-28 11:03:09 +0100 | [diff] [blame] | 885 | * <p>The intent is only sent to the new device or profile owner. |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 886 | * |
| 887 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 888 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 889 | */ |
| 890 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 891 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 892 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 893 | |
| 894 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 895 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 896 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 897 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 898 | * <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] | 899 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 900 | * |
| 901 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 902 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 903 | */ |
| 904 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 905 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 906 | |
| 907 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 908 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 909 | * provisioning. If this extra is not passed, a default image will be shown. |
| 910 | * <h5>The following URI schemes are accepted:</h5> |
| 911 | * <ul> |
| 912 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 913 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 914 | * </ul> |
| 915 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 916 | * <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] | 917 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 918 | * |
| 919 | * <p> If a content: URI is passed, the intent should have the flag |
| 920 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 921 | * {@link android.content.ClipData} of the intent too. |
| 922 | * |
| 923 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 924 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 925 | */ |
| 926 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 927 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 928 | |
| 929 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 930 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 931 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 932 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 933 | * content. |
| 934 | * |
| 935 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 936 | * management application (MDM), and one disclaimer from the organization. |
| 937 | * |
| 938 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 939 | * |
| 940 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 941 | * |
| 942 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 943 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 944 | */ |
| 945 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 946 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 947 | |
| 948 | /** |
| 949 | * A String extra of localized disclaimer header. |
| 950 | * |
| 951 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 952 | * or the organization name. |
| 953 | * |
| 954 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 955 | * |
| 956 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 957 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 958 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 959 | * |
| 960 | * <pre> |
| 961 | * <meta-data |
| 962 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 963 | * android:resource="@string/disclaimer_header" |
| 964 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 965 | */ |
| 966 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 967 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 968 | |
| 969 | /** |
| 970 | * A {@link Uri} extra pointing to disclaimer content. |
| 971 | * |
| 972 | * <h5>The following URI schemes are accepted:</h5> |
| 973 | * <ul> |
| 974 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 975 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 976 | * </ul> |
| 977 | * |
| 978 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 979 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 980 | * {@link android.widget.TextView}. |
| 981 | * |
| 982 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 983 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 984 | * {@link android.content.ClipData} of the intent too. |
| 985 | * |
| 986 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 987 | * |
| 988 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 989 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 990 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 991 | * |
| 992 | * <pre> |
| 993 | * <meta-data |
| 994 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 995 | * android:resource="@string/disclaimer_content" |
| 996 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 997 | */ |
| 998 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 999 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 1000 | |
| 1001 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 1002 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 1003 | * during setup-wizard. |
| 1004 | * |
| 1005 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 1006 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 1007 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 1008 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 1009 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 1010 | * |
| 1011 | * @hide |
| 1012 | */ |
| 1013 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 1014 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 1015 | |
| 1016 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 1017 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 1018 | * skipped. If unspecified, defaults to {@code false}. |
| 1019 | * |
| 1020 | * It can only be used by an existing device owner trying to create a managed profile via |
| 1021 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 1022 | */ |
| 1023 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 1024 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 1025 | |
| 1026 | /** |
Alex Chau | eca99a0 | 2018-04-30 17:51:56 +0100 | [diff] [blame] | 1027 | * A boolean extra indicating if mobile data should be used during NFC device owner provisioning |
| 1028 | * for downloading the mobile device management application. If {@link |
| 1029 | * #EXTRA_PROVISIONING_WIFI_SSID} is also specified, wifi network will be used instead. |
| 1030 | * |
| 1031 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 1032 | * provisioning via an NFC bump. |
| 1033 | * |
| 1034 | * @hide |
| 1035 | */ |
| 1036 | public static final String EXTRA_PROVISIONING_USE_MOBILE_DATA = |
| 1037 | "android.app.extra.PROVISIONING_USE_MOBILE_DATA"; |
| 1038 | |
| 1039 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1040 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1041 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 1042 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 1043 | * A device owner has full control over the device. The device owner can not be modified by the |
| 1044 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 1045 | * reset. |
| 1046 | * |
| 1047 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 1048 | * employee or client. |
| 1049 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1050 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1051 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 1052 | * <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] | 1053 | * contains the following properties: |
| 1054 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1055 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 1056 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 1057 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1058 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1059 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1060 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1061 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1062 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1063 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1064 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1065 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1066 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1067 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1068 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1069 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1070 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1071 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1072 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1073 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1074 | * 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] | 1075 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1076 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1077 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1078 | */ |
| 1079 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1080 | = "application/com.android.managedprovisioning"; |
| 1081 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1082 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1083 | * Activity action: ask the user to add a new device administrator to the system. |
| 1084 | * The desired policy is the ComponentName of the policy in the |
| 1085 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1086 | * bring the user through adding the device administrator to the system (or |
| 1087 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1088 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1089 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1090 | * field to provide the user with additional explanation (in addition |
| 1091 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1092 | * |
| 1093 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1094 | * user intervention). However, if your administrator has been updated and is requesting |
| 1095 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1096 | * 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] | 1097 | */ |
| 1098 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1099 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1100 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1101 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1102 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1103 | * @hide |
| 1104 | * 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] | 1105 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1106 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1107 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1108 | * 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] | 1109 | * to remotely control restrictions on the user. |
| 1110 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1111 | * <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] | 1112 | * result of whether or not the user approved the action. If approved, the result will |
| 1113 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1114 | * as a profile owner. |
| 1115 | * |
| 1116 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1117 | * field to provide the user with additional explanation (in addition |
| 1118 | * to your component's description) about what is being added. |
| 1119 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1120 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1121 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1122 | */ |
| 1123 | @SystemApi |
| 1124 | public static final String ACTION_SET_PROFILE_OWNER |
| 1125 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1126 | |
| 1127 | /** |
| 1128 | * @hide |
| 1129 | * Name of the profile owner admin that controls the user. |
| 1130 | */ |
| 1131 | @SystemApi |
| 1132 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1133 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1134 | |
| 1135 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1136 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1137 | * 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] | 1138 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1139 | * @hide |
| 1140 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1141 | @UnsupportedAppUsage |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1142 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1143 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1144 | |
| 1145 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1146 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1147 | * |
| 1148 | * This broadcast is sent only to the primary user. |
| 1149 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 1150 | * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle) |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1151 | */ |
| 1152 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1153 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1154 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1155 | |
| 1156 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1157 | * The ComponentName of the administrator component. |
| 1158 | * |
| 1159 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1160 | */ |
| 1161 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1162 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1163 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1164 | * An optional CharSequence providing additional explanation for why the |
| 1165 | * admin is being added. |
| 1166 | * |
| 1167 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1168 | */ |
| 1169 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1170 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1171 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1172 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1173 | * {@link #createAdminSupportIntent(String)}. |
| 1174 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1175 | */ |
| 1176 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1177 | |
| 1178 | /** |
| 1179 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1180 | * {@link #createAdminSupportIntent(String)}. |
| 1181 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1182 | */ |
| 1183 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1184 | |
| 1185 | /** |
Lenka Trochtova | 16a91c0 | 2018-01-17 11:03:30 +0100 | [diff] [blame] | 1186 | * Constant to indicate the feature of mandatory backups. Used as argument to |
| 1187 | * {@link #createAdminSupportIntent(String)}. |
| 1188 | * @see #setMandatoryBackupTransport(ComponentName, ComponentName) |
Lenka Trochtova | 27fd821 | 2018-04-10 11:01:58 +0200 | [diff] [blame] | 1189 | * @hide |
Lenka Trochtova | 16a91c0 | 2018-01-17 11:03:30 +0100 | [diff] [blame] | 1190 | */ |
| 1191 | public static final String POLICY_MANDATORY_BACKUPS = "policy_mandatory_backups"; |
| 1192 | |
| 1193 | /** |
Tony Mak | 706fbe7 | 2018-04-03 18:49:05 +0100 | [diff] [blame] | 1194 | * Constant to indicate the feature of suspending app. Use it as the value of |
| 1195 | * {@link #EXTRA_RESTRICTION}. |
| 1196 | * @hide |
| 1197 | */ |
| 1198 | public static final String POLICY_SUSPEND_PACKAGES = "policy_suspend_packages"; |
| 1199 | |
| 1200 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1201 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1202 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
Lenka Trochtova | 16a91c0 | 2018-01-17 11:03:30 +0100 | [diff] [blame] | 1203 | * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE} or |
| 1204 | * {@link #POLICY_MANDATORY_BACKUPS}. |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1205 | * @see #createAdminSupportIntent(String) |
| 1206 | * @hide |
| 1207 | */ |
| 1208 | @TestApi |
| 1209 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1210 | |
| 1211 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1212 | * Activity action: have the user enter a new password. This activity should |
| 1213 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1214 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1215 | * enter a new password that meets the current requirements. You can use |
| 1216 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1217 | * have the user select a new password in order to meet the current |
| 1218 | * constraints. Upon being resumed from this activity, you can check the new |
| 1219 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1220 | * |
| 1221 | * If the intent is launched from within a managed profile with a profile |
| 1222 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1223 | * this will trigger entering a new password for the parent of the profile. |
| 1224 | * For all other cases it will trigger entering a new password for the user |
| 1225 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1226 | * |
| 1227 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1228 | */ |
| 1229 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1230 | public static final String ACTION_SET_NEW_PASSWORD |
| 1231 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1232 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1233 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1234 | * Activity action: have the user enter a new password for the parent profile. |
| 1235 | * If the intent is launched from within a managed profile, this will trigger |
| 1236 | * entering a new password for the parent of the profile. In all other cases |
| 1237 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1238 | */ |
| 1239 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1240 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1241 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1242 | |
| 1243 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1244 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1245 | * Network logging was enabled and the user tapped the notification. |
| 1246 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1247 | * @hide |
| 1248 | */ |
| 1249 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1250 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1251 | |
| 1252 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1253 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1254 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1255 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1256 | * |
| 1257 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1258 | */ |
| 1259 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1260 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1261 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1262 | |
| 1263 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1264 | * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1265 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1266 | */ |
| 1267 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1268 | |
| 1269 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1270 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1271 | * the parent profile to access intents sent from the managed profile. |
| 1272 | * That is, when an app in the managed profile calls |
| 1273 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1274 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1275 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1276 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1277 | |
| 1278 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1279 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1280 | * the managed profile to access intents sent from the parent profile. |
| 1281 | * That is, when an app in the parent profile calls |
| 1282 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1283 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1284 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1285 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1286 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1287 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1288 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1289 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1290 | */ |
| 1291 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1292 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1293 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1294 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1295 | /** |
Rubin Xu | cc391c2 | 2018-01-02 20:37:35 +0000 | [diff] [blame] | 1296 | * Broadcast action to notify ManagedProvisioning that |
| 1297 | * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction has changed. |
| 1298 | * @hide |
| 1299 | */ |
| 1300 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1301 | public static final String ACTION_DATA_SHARING_RESTRICTION_CHANGED = |
| 1302 | "android.app.action.DATA_SHARING_RESTRICTION_CHANGED"; |
| 1303 | |
| 1304 | /** |
| 1305 | * Broadcast action from ManagedProvisioning to notify that the latest change to |
| 1306 | * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction has been successfully |
| 1307 | * applied (cross profile intent filters updated). Only usesd for CTS tests. |
| 1308 | * @hide |
| 1309 | */ |
| 1310 | @TestApi |
| 1311 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1312 | public static final String ACTION_DATA_SHARING_RESTRICTION_APPLIED = |
| 1313 | "android.app.action.DATA_SHARING_RESTRICTION_APPLIED"; |
| 1314 | |
| 1315 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1316 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1317 | * Already granted or denied permissions are not affected by this. |
| 1318 | */ |
| 1319 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1320 | |
| 1321 | /** |
| 1322 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1323 | * Already granted or denied permissions are not affected by this. |
| 1324 | */ |
| 1325 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1326 | |
| 1327 | /** |
| 1328 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1329 | * Already granted or denied permissions are not affected by this. |
| 1330 | */ |
| 1331 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1332 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1333 | /** |
| 1334 | * Runtime permission state: The user can manage the permission |
| 1335 | * through the UI. |
| 1336 | */ |
| 1337 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1338 | |
| 1339 | /** |
| 1340 | * Runtime permission state: The permission is granted to the app |
| 1341 | * and the user cannot manage the permission through the UI. |
| 1342 | */ |
| 1343 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1344 | |
| 1345 | /** |
| 1346 | * Runtime permission state: The permission is denied to the app |
| 1347 | * and the user cannot manage the permission through the UI. |
| 1348 | */ |
| 1349 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1350 | |
| 1351 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1352 | * Delegation of certificate installation and management. This scope grants access to the |
| 1353 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1354 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1355 | */ |
| 1356 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1357 | |
| 1358 | /** |
| 1359 | * Delegation of application restrictions management. This scope grants access to the |
| 1360 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1361 | */ |
| 1362 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1363 | |
| 1364 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1365 | * Delegation of application uninstall block. This scope grants access to the |
| 1366 | * {@link #setUninstallBlocked} API. |
| 1367 | */ |
| 1368 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1369 | |
| 1370 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1371 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1372 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1373 | * and {@link #setPermissionGrantState} APIs. |
| 1374 | */ |
| 1375 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1376 | |
| 1377 | /** |
| 1378 | * Delegation of package access state. This scope grants access to the |
| 1379 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1380 | * {@link #setPackagesSuspended} APIs. |
| 1381 | */ |
| 1382 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1383 | |
| 1384 | /** |
| 1385 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1386 | * API. |
| 1387 | */ |
| 1388 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1389 | |
| 1390 | /** |
Alex Chau | 5343fcb | 2017-12-05 16:49:19 +0000 | [diff] [blame] | 1391 | * Delegation for installing existing packages. This scope grants access to the |
| 1392 | * {@link #installExistingPackage} API. |
| 1393 | */ |
| 1394 | public static final String DELEGATION_INSTALL_EXISTING_PACKAGE = |
| 1395 | "delegation-install-existing-package"; |
| 1396 | |
| 1397 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1398 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1399 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1400 | */ |
| 1401 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1402 | "delegation-keep-uninstalled-packages"; |
| 1403 | |
| 1404 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1405 | * No management for current user in-effect. This is the default. |
| 1406 | * @hide |
| 1407 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1408 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1409 | public static final int STATE_USER_UNMANAGED = 0; |
| 1410 | |
| 1411 | /** |
| 1412 | * Management partially setup, user setup needs to be completed. |
| 1413 | * @hide |
| 1414 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1415 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1416 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1417 | |
| 1418 | /** |
| 1419 | * Management partially setup, user setup completed. |
| 1420 | * @hide |
| 1421 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1422 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1423 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1424 | |
| 1425 | /** |
| 1426 | * Management setup and active on current user. |
| 1427 | * @hide |
| 1428 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1429 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1430 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1431 | |
| 1432 | /** |
| 1433 | * Management partially setup on a managed profile. |
| 1434 | * @hide |
| 1435 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1436 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1437 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1438 | |
| 1439 | /** |
| 1440 | * @hide |
| 1441 | */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 1442 | @IntDef(prefix = { "STATE_USER_" }, value = { |
| 1443 | STATE_USER_UNMANAGED, |
| 1444 | STATE_USER_SETUP_INCOMPLETE, |
| 1445 | STATE_USER_SETUP_COMPLETE, |
| 1446 | STATE_USER_SETUP_FINALIZED, |
| 1447 | STATE_USER_PROFILE_COMPLETE |
| 1448 | }) |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1449 | @Retention(RetentionPolicy.SOURCE) |
| 1450 | public @interface UserProvisioningState {} |
| 1451 | |
| 1452 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1453 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1454 | * |
| 1455 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1456 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1457 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1458 | * |
| 1459 | * @hide |
| 1460 | */ |
| 1461 | public static final int CODE_OK = 0; |
| 1462 | |
| 1463 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1464 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1465 | * |
| 1466 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1467 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1468 | * owner. |
| 1469 | * |
| 1470 | * @hide |
| 1471 | */ |
| 1472 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1473 | |
| 1474 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1475 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1476 | * |
| 1477 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1478 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1479 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1480 | * |
| 1481 | * @hide |
| 1482 | */ |
| 1483 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1484 | |
| 1485 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1486 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1487 | * |
| 1488 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1489 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1490 | * |
| 1491 | * @hide |
| 1492 | */ |
| 1493 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1494 | |
| 1495 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1496 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1497 | * |
| 1498 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1499 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1500 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1501 | * |
| 1502 | * @hide |
| 1503 | */ |
| 1504 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1505 | |
| 1506 | /** |
| 1507 | * Code used to indicate that the device also has a user other than the system user. |
| 1508 | * |
| 1509 | * @hide |
| 1510 | */ |
| 1511 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1512 | |
| 1513 | /** |
| 1514 | * Code used to indicate that device has an account that prevents provisioning. |
| 1515 | * |
| 1516 | * @hide |
| 1517 | */ |
| 1518 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1519 | |
| 1520 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1521 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1522 | * |
| 1523 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1524 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1525 | * |
| 1526 | * @hide |
| 1527 | */ |
| 1528 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1529 | |
| 1530 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1531 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1532 | * |
| 1533 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1534 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1535 | * when the device is a watch and is already paired. |
| 1536 | * |
| 1537 | * @hide |
| 1538 | */ |
| 1539 | public static final int CODE_HAS_PAIRED = 8; |
| 1540 | |
| 1541 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1542 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1543 | * |
| 1544 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1545 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1546 | * |
| 1547 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1548 | * @hide |
| 1549 | */ |
| 1550 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1551 | |
| 1552 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1553 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1554 | * |
| 1555 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1556 | * |
| 1557 | * @hide |
| 1558 | */ |
| 1559 | public static final int CODE_SYSTEM_USER = 10; |
| 1560 | |
| 1561 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1562 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1563 | * |
| 1564 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1565 | * managed profiles. |
| 1566 | * |
| 1567 | * @hide |
| 1568 | */ |
| 1569 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1570 | |
| 1571 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1572 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1573 | * |
| 1574 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1575 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1576 | * user. |
| 1577 | * |
| 1578 | * @hide |
| 1579 | */ |
| 1580 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1581 | |
| 1582 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1583 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1584 | * |
| 1585 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1586 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1587 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1588 | * admins. |
| 1589 | * |
| 1590 | * @hide |
| 1591 | */ |
| 1592 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1593 | |
| 1594 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1595 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1596 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1597 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1598 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1599 | * |
| 1600 | * @hide |
| 1601 | */ |
| 1602 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1603 | |
| 1604 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1605 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1606 | * |
| 1607 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1608 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1609 | * |
| 1610 | * @hide |
| 1611 | */ |
| 1612 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1613 | |
| 1614 | /** |
| 1615 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1616 | * conditions. |
| 1617 | * |
| 1618 | * @hide |
| 1619 | */ |
| 1620 | @Retention(RetentionPolicy.SOURCE) |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 1621 | @IntDef(prefix = { "CODE_" }, value = { |
| 1622 | CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1623 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1624 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1625 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 1626 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED |
| 1627 | }) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1628 | public @interface ProvisioningPreCondition {} |
| 1629 | |
| 1630 | /** |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1631 | * Disable all configurable SystemUI features during LockTask mode. This includes, |
| 1632 | * <ul> |
| 1633 | * <li>system info area in the status bar (connectivity icons, clock, etc.) |
| 1634 | * <li>notifications (including alerts, icons, and the notification shade) |
| 1635 | * <li>Home button |
| 1636 | * <li>Recents button and UI |
| 1637 | * <li>global actions menu (i.e. power button menu) |
| 1638 | * <li>keyguard |
| 1639 | * </ul> |
| 1640 | * |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1641 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1642 | */ |
| 1643 | public static final int LOCK_TASK_FEATURE_NONE = 0; |
| 1644 | |
| 1645 | /** |
| 1646 | * Enable the system info area in the status bar during LockTask mode. The system info area |
| 1647 | * usually occupies the right side of the status bar (although this can differ across OEMs). It |
| 1648 | * includes all system information indicators, such as date and time, connectivity, battery, |
| 1649 | * vibration mode, etc. |
| 1650 | * |
| 1651 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1652 | */ |
| 1653 | public static final int LOCK_TASK_FEATURE_SYSTEM_INFO = 1; |
| 1654 | |
| 1655 | /** |
| 1656 | * Enable notifications during LockTask mode. This includes notification icons on the status |
| 1657 | * bar, heads-up notifications, and the expandable notification shade. Note that the Quick |
Benjamin Franz | 78ae106 | 2018-03-26 11:01:32 +0100 | [diff] [blame] | 1658 | * Settings panel remains disabled. This feature flag can only be used in combination with |
| 1659 | * {@link #LOCK_TASK_FEATURE_HOME}. {@link #setLockTaskFeatures(ComponentName, int)} |
| 1660 | * throws an {@link IllegalArgumentException} if this feature flag is defined without |
| 1661 | * {@link #LOCK_TASK_FEATURE_HOME}. |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1662 | * |
| 1663 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1664 | */ |
| 1665 | public static final int LOCK_TASK_FEATURE_NOTIFICATIONS = 1 << 1; |
| 1666 | |
| 1667 | /** |
| 1668 | * Enable the Home button during LockTask mode. Note that if a custom launcher is used, it has |
| 1669 | * to be registered as the default launcher with |
| 1670 | * {@link #addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}, and its |
| 1671 | * package needs to be whitelisted for LockTask with |
| 1672 | * {@link #setLockTaskPackages(ComponentName, String[])}. |
| 1673 | * |
| 1674 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1675 | */ |
| 1676 | public static final int LOCK_TASK_FEATURE_HOME = 1 << 2; |
| 1677 | |
| 1678 | /** |
Benjamin Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 1679 | * Enable the Overview button and the Overview screen during LockTask mode. This feature flag |
| 1680 | * can only be used in combination with {@link #LOCK_TASK_FEATURE_HOME}, and |
| 1681 | * {@link #setLockTaskFeatures(ComponentName, int)} will throw an |
| 1682 | * {@link IllegalArgumentException} if this feature flag is defined without |
| 1683 | * {@link #LOCK_TASK_FEATURE_HOME}. |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1684 | * |
| 1685 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1686 | */ |
Benjamin Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 1687 | public static final int LOCK_TASK_FEATURE_OVERVIEW = 1 << 3; |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1688 | |
| 1689 | /** |
| 1690 | * Enable the global actions dialog during LockTask mode. This is the dialog that shows up when |
| 1691 | * the user long-presses the power button, for example. Note that the user may not be able to |
| 1692 | * power off the device if this flag is not set. |
| 1693 | * |
Benjamin Franz | 78ae106 | 2018-03-26 11:01:32 +0100 | [diff] [blame] | 1694 | * <p>This flag is enabled by default until {@link #setLockTaskFeatures(ComponentName, int)} is |
| 1695 | * called for the first time. |
| 1696 | * |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1697 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1698 | */ |
| 1699 | public static final int LOCK_TASK_FEATURE_GLOBAL_ACTIONS = 1 << 4; |
| 1700 | |
| 1701 | /** |
| 1702 | * Enable the keyguard during LockTask mode. Note that if the keyguard is already disabled with |
| 1703 | * {@link #setKeyguardDisabled(ComponentName, boolean)}, setting this flag will have no effect. |
| 1704 | * If this flag is not set, the keyguard will not be shown even if the user has a lock screen |
| 1705 | * credential. |
| 1706 | * |
| 1707 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1708 | */ |
| 1709 | public static final int LOCK_TASK_FEATURE_KEYGUARD = 1 << 5; |
| 1710 | |
| 1711 | /** |
| 1712 | * Flags supplied to {@link #setLockTaskFeatures(ComponentName, int)}. |
| 1713 | * |
| 1714 | * @hide |
| 1715 | */ |
| 1716 | @Retention(RetentionPolicy.SOURCE) |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 1717 | @IntDef(flag = true, prefix = { "LOCK_TASK_FEATURE_" }, value = { |
| 1718 | LOCK_TASK_FEATURE_NONE, |
| 1719 | LOCK_TASK_FEATURE_SYSTEM_INFO, |
| 1720 | LOCK_TASK_FEATURE_NOTIFICATIONS, |
| 1721 | LOCK_TASK_FEATURE_HOME, |
Benjamin Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 1722 | LOCK_TASK_FEATURE_OVERVIEW, |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 1723 | LOCK_TASK_FEATURE_GLOBAL_ACTIONS, |
| 1724 | LOCK_TASK_FEATURE_KEYGUARD |
| 1725 | }) |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1726 | public @interface LockTaskFeature {} |
| 1727 | |
| 1728 | /** |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1729 | * Service action: Action for a service that device owner and profile owner can optionally |
| 1730 | * own. If a device owner or a profile owner has such a service, the system tries to keep |
| 1731 | * a bound connection to it, in order to keep their process always running. |
Makoto Onuki | fe73970 | 2017-04-25 13:26:21 -0700 | [diff] [blame] | 1732 | * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN} |
| 1733 | * permission. |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1734 | */ |
| 1735 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
| 1736 | public static final String ACTION_DEVICE_ADMIN_SERVICE |
| 1737 | = "android.app.action.DEVICE_ADMIN_SERVICE"; |
| 1738 | |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 1739 | /** @hide */ |
| 1740 | @Retention(RetentionPolicy.SOURCE) |
| 1741 | @IntDef(flag = true, prefix = {"ID_TYPE_"}, value = { |
| 1742 | ID_TYPE_BASE_INFO, |
| 1743 | ID_TYPE_SERIAL, |
| 1744 | ID_TYPE_IMEI, |
| 1745 | ID_TYPE_MEID |
| 1746 | }) |
| 1747 | public @interface AttestationIdType {} |
| 1748 | |
| 1749 | /** |
| 1750 | * Specifies that the device should attest its manufacturer details. For use with |
| 1751 | * {@link #generateKeyPair}. |
| 1752 | * |
| 1753 | * @see #generateKeyPair |
| 1754 | */ |
| 1755 | public static final int ID_TYPE_BASE_INFO = 1; |
| 1756 | |
| 1757 | /** |
| 1758 | * Specifies that the device should attest its serial number. For use with |
| 1759 | * {@link #generateKeyPair}. |
| 1760 | * |
| 1761 | * @see #generateKeyPair |
| 1762 | */ |
| 1763 | public static final int ID_TYPE_SERIAL = 2; |
| 1764 | |
| 1765 | /** |
| 1766 | * Specifies that the device should attest its IMEI. For use with {@link #generateKeyPair}. |
| 1767 | * |
| 1768 | * @see #generateKeyPair |
| 1769 | */ |
| 1770 | public static final int ID_TYPE_IMEI = 4; |
| 1771 | |
| 1772 | /** |
| 1773 | * Specifies that the device should attest its MEID. For use with {@link #generateKeyPair}. |
| 1774 | * |
| 1775 | * @see #generateKeyPair |
| 1776 | */ |
| 1777 | public static final int ID_TYPE_MEID = 8; |
| 1778 | |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1779 | /** |
Eran Messeri | f15d4f4 | 2018-03-23 13:32:17 +0000 | [diff] [blame] | 1780 | * Specifies that the calling app should be granted access to the installed credentials |
| 1781 | * immediately. Otherwise, access to the credentials will be gated by user approval. |
| 1782 | * For use with {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int)} |
| 1783 | * |
| 1784 | * @see #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int) |
| 1785 | */ |
| 1786 | public static final int INSTALLKEY_REQUEST_CREDENTIALS_ACCESS = 1; |
| 1787 | |
| 1788 | /** |
| 1789 | * Specifies that a user can select the key via the Certificate Selection prompt. |
| 1790 | * If this flag is not set when calling {@link #installKeyPair}, the key can only be granted |
| 1791 | * access by implementing {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias}. |
| 1792 | * For use with {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int)} |
| 1793 | * |
| 1794 | * @see #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int) |
| 1795 | */ |
| 1796 | public static final int INSTALLKEY_SET_USER_SELECTABLE = 2; |
| 1797 | |
| 1798 | /** |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 1799 | * Broadcast action: sent when the profile owner is set, changed or cleared. |
| 1800 | * |
| 1801 | * This broadcast is sent only to the user managed by the new profile owner. |
| 1802 | * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle) |
| 1803 | */ |
| 1804 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1805 | public static final String ACTION_PROFILE_OWNER_CHANGED = |
| 1806 | "android.app.action.PROFILE_OWNER_CHANGED"; |
| 1807 | |
| 1808 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1809 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1810 | * |
| 1811 | * @param admin The administrator component to check for. |
| 1812 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1813 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1814 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1815 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1816 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1817 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | /** |
| 1821 | * @see #isAdminActive(ComponentName) |
| 1822 | * @hide |
| 1823 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1824 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1825 | if (mService != null) { |
| 1826 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1827 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1828 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1829 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | return false; |
| 1833 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1834 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1835 | /** |
| 1836 | * Return true if the given administrator component is currently being removed |
| 1837 | * for the user. |
| 1838 | * @hide |
| 1839 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1840 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1841 | if (mService != null) { |
| 1842 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1843 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1844 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1845 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1846 | } |
| 1847 | } |
| 1848 | return false; |
| 1849 | } |
| 1850 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1851 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1852 | * Return a list of all currently active device administrators' component |
| 1853 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1854 | * returned. |
| 1855 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1856 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1857 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1858 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | /** |
| 1862 | * @see #getActiveAdmins() |
| 1863 | * @hide |
| 1864 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1865 | @UnsupportedAppUsage |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1866 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1867 | if (mService != null) { |
| 1868 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1869 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1870 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1871 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1872 | } |
| 1873 | } |
| 1874 | return null; |
| 1875 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1876 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1877 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1878 | * Used by package administration code to determine if a package can be stopped |
| 1879 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1880 | * @hide |
| 1881 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1882 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 1883 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1884 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1885 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1886 | } |
| 1887 | |
| 1888 | /** |
| 1889 | * Used by package administration code to determine if a package can be stopped |
| 1890 | * or uninstalled. |
| 1891 | * @hide |
| 1892 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1893 | @UnsupportedAppUsage |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1894 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1895 | if (mService != null) { |
| 1896 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1897 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1898 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1899 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | return false; |
| 1903 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1904 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1905 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1906 | * Remove a current administration component. This can only be called |
| 1907 | * by the application that owns the administration component; if you |
| 1908 | * try to remove someone else's component, a security exception will be |
| 1909 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1910 | * |
| 1911 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1912 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1913 | * |
| 1914 | * @param admin The administration compononent to remove. |
| 1915 | * @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] | 1916 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1917 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1918 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1919 | if (mService != null) { |
| 1920 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1921 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1922 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1923 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1927 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1928 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1929 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1930 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1931 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1932 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1933 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1934 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1935 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1936 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1937 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1938 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1939 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1940 | if (mService != null) { |
| 1941 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1942 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1943 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1944 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1945 | } |
| 1946 | } |
| 1947 | return false; |
| 1948 | } |
| 1949 | |
| 1950 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1951 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1952 | * |
| 1953 | * @hide |
| 1954 | */ |
| 1955 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1956 | if (mService != null) { |
| 1957 | try { |
| 1958 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1959 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1960 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | return false; |
| 1964 | } |
| 1965 | |
| 1966 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1967 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1968 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1969 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1970 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1971 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1972 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1973 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1974 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1975 | * recognition technology. This implies technologies that can recognize the identity of |
| 1976 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1977 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1978 | */ |
| 1979 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1980 | |
| 1981 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1982 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1983 | * 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] | 1984 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1985 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1986 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1987 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1988 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1989 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1990 | * password containing at least numeric characters. Note that quality |
| 1991 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1992 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1993 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1994 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1995 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1996 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1997 | * password containing at least numeric characters with no repeating (4444) |
| 1998 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1999 | * constants are ordered so that higher values are more restrictive. |
| 2000 | */ |
| 2001 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 2002 | |
| 2003 | /** |
| 2004 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 2005 | * password containing at least alphabetic (or other symbol) characters. |
| 2006 | * Note that quality constants are ordered so that higher values are more |
| 2007 | * restrictive. |
| 2008 | */ |
| 2009 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2010 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 2011 | /** |
| 2012 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2013 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 2014 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2015 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2016 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 2017 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2018 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2019 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2020 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2021 | * password containing at least a letter, a numerical digit and a special |
| 2022 | * symbol, by default. With this password quality, passwords can be |
| 2023 | * restricted to contain various sets of characters, like at least an |
| 2024 | * uppercase letter, etc. These are specified using various methods, |
| 2025 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 2026 | * that quality constants are ordered so that higher values are more |
| 2027 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2028 | */ |
| 2029 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 2030 | |
| 2031 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 2032 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 2033 | * modify password. In case this password quality is set, the password is |
| 2034 | * managed by a profile owner. The profile owner can set any password, |
| 2035 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 2036 | * that quality constants are ordered so that higher values are more |
| 2037 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 2038 | * the highest. |
| 2039 | * @hide |
| 2040 | */ |
| 2041 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 2042 | |
| 2043 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 2044 | * @hide |
| 2045 | * |
| 2046 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 2047 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 2048 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 2049 | * used by authenticator to exempt their accounts from this: |
| 2050 | * |
| 2051 | * <ul> |
| 2052 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 2053 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 2054 | * <application> tag in the manifest. |
| 2055 | * |
| 2056 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 2057 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 2058 | * Some authenticators claim to have any features, so to detect it, we also check |
| 2059 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 2060 | * if any of the accounts have it. |
| 2061 | * </ul> |
| 2062 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 2063 | @SystemApi |
| 2064 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 2065 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 2066 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 2067 | |
| 2068 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 2069 | @SystemApi |
| 2070 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 2071 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 2072 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 2073 | |
| 2074 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2075 | * Called by an application that is administering the device to set the password restrictions it |
| 2076 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 2077 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 2078 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 2079 | * 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] | 2080 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2081 | * <p> |
| 2082 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 2083 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 2084 | * considerations) is the one that is in effect. |
| 2085 | * <p> |
| 2086 | * The calling device admin must have requested |
| 2087 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2088 | * not, a security exception will be thrown. |
| 2089 | * <p> |
| 2090 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2091 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2092 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2093 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2094 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2095 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 2096 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 2097 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 2098 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2099 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 2100 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2101 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2102 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2103 | if (mService != null) { |
| 2104 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2105 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2106 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2107 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2111 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2112 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2113 | * 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] | 2114 | * 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] | 2115 | * a separate challenge are not taken into account. |
| 2116 | * |
| 2117 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2118 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2119 | * restrictions on the parent profile. |
| 2120 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2121 | * @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] | 2122 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2123 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2124 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2125 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2129 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2130 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2131 | if (mService != null) { |
| 2132 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2133 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2134 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2135 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2136 | } |
| 2137 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2138 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2139 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2140 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2141 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2142 | * Called by an application that is administering the device to set the minimum allowed password |
| 2143 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 2144 | * least as restrictive as what has been set. Note that the current password will remain until |
| 2145 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 2146 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2147 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2148 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2149 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 2150 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2151 | * {@link #setPasswordQuality}. |
| 2152 | * <p> |
| 2153 | * The calling device admin must have requested |
| 2154 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2155 | * not, a security exception will be thrown. |
| 2156 | * <p> |
| 2157 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2158 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2159 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2160 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2161 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2162 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 2163 | * restriction. |
| 2164 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2165 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2166 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2167 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2168 | if (mService != null) { |
| 2169 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2170 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2171 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2172 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2176 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2177 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2178 | * 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] | 2179 | * 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] | 2180 | * a separate challenge are not taken into account. |
| 2181 | * |
| 2182 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2183 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2184 | * restrictions on the parent profile. |
| 2185 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2186 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2187 | * @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] | 2188 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2189 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2190 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2191 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2195 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2196 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2197 | if (mService != null) { |
| 2198 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2199 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2200 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2201 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | return 0; |
| 2205 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2206 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2207 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2208 | * Called by an application that is administering the device to set the minimum number of upper |
| 2209 | * case letters required in the password. After setting this, the user will not be able to enter |
| 2210 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 2211 | * current password will remain until the user has set a new one, so the change does not take |
| 2212 | * place immediately. To prompt the user for a new password, use |
| 2213 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2214 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2215 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2216 | * <p> |
| 2217 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2218 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2219 | * not, a security exception will be thrown. |
| 2220 | * <p> |
| 2221 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2222 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2223 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2224 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2225 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2226 | * @param length The new desired minimum number of upper case letters required in the password. |
| 2227 | * A value of 0 means there is no restriction. |
| 2228 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2229 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2230 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2231 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2232 | if (mService != null) { |
| 2233 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2234 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2235 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2236 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2237 | } |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2242 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2243 | * 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] | 2244 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 2245 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2246 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2247 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2248 | * and only applies when the password quality is |
| 2249 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2250 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2251 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2252 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2253 | * restrictions on the parent profile. |
| 2254 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2255 | * @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] | 2256 | * aggregate all admins. |
| 2257 | * @return The minimum number of upper case letters required in the |
| 2258 | * password. |
| 2259 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2260 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2261 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2265 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2266 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2267 | if (mService != null) { |
| 2268 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2269 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2270 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2271 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2272 | } |
| 2273 | } |
| 2274 | return 0; |
| 2275 | } |
| 2276 | |
| 2277 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2278 | * Called by an application that is administering the device to set the minimum number of lower |
| 2279 | * case letters required in the password. After setting this, the user will not be able to enter |
| 2280 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 2281 | * current password will remain until the user has set a new one, so the change does not take |
| 2282 | * place immediately. To prompt the user for a new password, use |
| 2283 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2284 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2285 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2286 | * <p> |
| 2287 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2288 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2289 | * not, a security exception will be thrown. |
| 2290 | * <p> |
| 2291 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2292 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2293 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2294 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2295 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2296 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2297 | * A value of 0 means there is no restriction. |
| 2298 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2299 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2300 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2301 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2302 | if (mService != null) { |
| 2303 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2304 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2305 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2306 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2307 | } |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2312 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2313 | * 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] | 2314 | * and its participating profiles. Restrictions on profiles that have |
| 2315 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2316 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2317 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2318 | * and only applies when the password quality is |
| 2319 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2320 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2321 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2322 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2323 | * restrictions on the parent profile. |
| 2324 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2325 | * @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] | 2326 | * aggregate all admins. |
| 2327 | * @return The minimum number of lower case letters required in the |
| 2328 | * password. |
| 2329 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2330 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2331 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2335 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2336 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2337 | if (mService != null) { |
| 2338 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2339 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2340 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2341 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | return 0; |
| 2345 | } |
| 2346 | |
| 2347 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2348 | * Called by an application that is administering the device to set the minimum number of |
| 2349 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2350 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2351 | * password will remain until the user has set a new one, so the change does not take place |
| 2352 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2353 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2354 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2355 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2356 | * <p> |
| 2357 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2358 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2359 | * not, a security exception will be thrown. |
| 2360 | * <p> |
| 2361 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2362 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2363 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2364 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2365 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2366 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2367 | * 0 means there is no restriction. |
| 2368 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2369 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2370 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2371 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2372 | if (mService != null) { |
| 2373 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2374 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2375 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2376 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2382 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2383 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2384 | * and its participating profiles. Restrictions on profiles that have |
| 2385 | * a separate challenge are not taken into account. |
| 2386 | * This is the same value as set by |
| 2387 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2388 | * and only applies when the password quality is |
| 2389 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2390 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2391 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2392 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2393 | * restrictions on the parent profile. |
| 2394 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2395 | * @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] | 2396 | * aggregate all admins. |
| 2397 | * @return The minimum number of letters required in the password. |
| 2398 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2399 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2400 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2404 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2405 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2406 | if (mService != null) { |
| 2407 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2408 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2409 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2410 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2411 | } |
| 2412 | } |
| 2413 | return 0; |
| 2414 | } |
| 2415 | |
| 2416 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2417 | * Called by an application that is administering the device to set the minimum number of |
| 2418 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2419 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2420 | * current password will remain until the user has set a new one, so the change does not take |
| 2421 | * place immediately. To prompt the user for a new password, use |
| 2422 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2423 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2424 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2425 | * <p> |
| 2426 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2427 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2428 | * not, a security exception will be thrown. |
| 2429 | * <p> |
| 2430 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2431 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2432 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2433 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2434 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2435 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2436 | * value of 0 means there is no restriction. |
| 2437 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2438 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2439 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2440 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2441 | if (mService != null) { |
| 2442 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2443 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2444 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2445 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | /** |
| 2451 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2452 | * 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] | 2453 | * and its participating profiles. Restrictions on profiles that have |
| 2454 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2455 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2456 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2457 | * and only applies when the password quality is |
| 2458 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2459 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2460 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2461 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2462 | * restrictions on the parent profile. |
| 2463 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2464 | * @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] | 2465 | * aggregate all admins. |
| 2466 | * @return The minimum number of numerical digits required in the password. |
| 2467 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2468 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2469 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2473 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2474 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2475 | if (mService != null) { |
| 2476 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2477 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2478 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2479 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
| 2485 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2486 | * Called by an application that is administering the device to set the minimum number of |
| 2487 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2488 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2489 | * password will remain until the user has set a new one, so the change does not take place |
| 2490 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2491 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2492 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2493 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2494 | * <p> |
| 2495 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2496 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2497 | * not, a security exception will be thrown. |
| 2498 | * <p> |
| 2499 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2500 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2501 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2502 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2503 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2504 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2505 | * 0 means there is no restriction. |
| 2506 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2507 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2508 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2509 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2510 | if (mService != null) { |
| 2511 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2512 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2513 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2514 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2520 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2521 | * 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] | 2522 | * and its participating profiles. Restrictions on profiles that have |
| 2523 | * a separate challenge are not taken into account. This is the same value as |
| 2524 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2525 | * and only applies when the password quality is |
| 2526 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2527 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2528 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2529 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2530 | * restrictions on the parent profile. |
| 2531 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2532 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2533 | * aggregate all admins. |
| 2534 | * @return The minimum number of symbols required in the password. |
| 2535 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2536 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2537 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2541 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2542 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2543 | if (mService != null) { |
| 2544 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2545 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2547 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | return 0; |
| 2551 | } |
| 2552 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2553 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2554 | * Called by an application that is administering the device to set the minimum number of |
| 2555 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2556 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2557 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2558 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2559 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2560 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2561 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2562 | * <p> |
| 2563 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2564 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2565 | * not, a security exception will be thrown. |
| 2566 | * <p> |
| 2567 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2568 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2569 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2570 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2571 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2572 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2573 | * 0 means there is no restriction. |
| 2574 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2575 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2576 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2577 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2578 | if (mService != null) { |
| 2579 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2580 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2581 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2582 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2588 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2589 | * 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] | 2590 | * and its participating profiles. Restrictions on profiles that have |
| 2591 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2592 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2593 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2594 | * and only applies when the password quality is |
| 2595 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2596 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2597 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2598 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2599 | * restrictions on the parent profile. |
| 2600 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2601 | * @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] | 2602 | * aggregate all admins. |
| 2603 | * @return The minimum number of letters required in the password. |
| 2604 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2605 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2606 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2610 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2611 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2612 | if (mService != null) { |
| 2613 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2614 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2615 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2616 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2617 | } |
| 2618 | } |
| 2619 | return 0; |
| 2620 | } |
| 2621 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2622 | /** |
| 2623 | * Called by an application that is administering the device to set the length of the password |
| 2624 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2625 | * same as any password in the history. Note that the current password will remain until the |
| 2626 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2627 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2628 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2629 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2630 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2631 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2632 | * <p> |
| 2633 | * The calling device admin must have requested |
| 2634 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2635 | * not, a security exception will be thrown. |
| 2636 | * <p> |
| 2637 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2638 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2639 | * profile. |
| 2640 | * |
| 2641 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2642 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2643 | * restriction. |
| 2644 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2645 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2646 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2647 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2648 | if (mService != null) { |
| 2649 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2650 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2651 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2652 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2658 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2659 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2660 | * device password (for all admins). |
| 2661 | * <p> |
| 2662 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2663 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2664 | * 432000000 ms for timeout. |
| 2665 | * <p> |
| 2666 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2667 | * <p> |
| 2668 | * The calling device admin must have requested |
| 2669 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2670 | * not, a security exception will be thrown. |
| 2671 | * <p> |
| 2672 | * Note that setting the password will automatically reset the expiration time for all active |
| 2673 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2674 | * <p> |
| 2675 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2676 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2677 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2678 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2679 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2680 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2681 | * there is no restriction (unlimited). |
| 2682 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2683 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2684 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2685 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2686 | if (mService != null) { |
| 2687 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2688 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2689 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2690 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2696 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2697 | * recurring expiration timeout provided in the call to |
| 2698 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2699 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2700 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2701 | * |
| 2702 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2703 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2704 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2705 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2706 | * @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] | 2707 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2708 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2709 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2710 | if (mService != null) { |
| 2711 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2712 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2713 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2714 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2715 | } |
| 2716 | } |
| 2717 | return 0; |
| 2718 | } |
| 2719 | |
| 2720 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2721 | * 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] | 2722 | * 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] | 2723 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2724 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2725 | * |
| 2726 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2727 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2728 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2729 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2730 | * @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] | 2731 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2732 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2733 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2734 | if (mService != null) { |
| 2735 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2736 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2737 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2738 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2739 | } |
| 2740 | } |
| 2741 | return 0; |
| 2742 | } |
| 2743 | |
| 2744 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2745 | * 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] | 2746 | * 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] | 2747 | * have a separate challenge are not taken into account. |
| 2748 | * |
| 2749 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2750 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2751 | * restrictions on the parent profile. |
| 2752 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2753 | * @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] | 2754 | * all admins. |
| 2755 | * @return The length of the password history |
| 2756 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2757 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2758 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | /** @hide per-user version */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 2762 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2763 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2764 | if (mService != null) { |
| 2765 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2766 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2767 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2768 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2769 | } |
| 2770 | } |
| 2771 | return 0; |
| 2772 | } |
| 2773 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2774 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2775 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2776 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2777 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2778 | * @return Returns the maximum length that the user can enter. |
| 2779 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2780 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2781 | // Kind-of arbitrary. |
| 2782 | return 16; |
| 2783 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2784 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2785 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2786 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2787 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2788 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
Benjamin Miller | cc12c5f | 2018-04-16 12:54:43 +0000 | [diff] [blame] | 2789 | * 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] | 2790 | * <p> |
| 2791 | * The calling device admin must have requested |
| 2792 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2793 | * not, a security exception will be thrown. |
| 2794 | * <p> |
| 2795 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2796 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2797 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2798 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2799 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2800 | * @throws SecurityException if the calling application does not own an active administrator |
| 2801 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Rubin Xu | 7cf4509 | 2017-08-28 11:47:35 +0100 | [diff] [blame] | 2802 | * @throws IllegalStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2803 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2804 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2805 | if (mService != null) { |
| 2806 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2807 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2808 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2809 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2810 | } |
| 2811 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2812 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2813 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2814 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2815 | /** |
Pavel Grafov | c4f87e9 | 2017-10-26 16:34:25 +0100 | [diff] [blame] | 2816 | * When called by a profile owner of a managed profile returns true if the profile uses unified |
| 2817 | * challenge with its parent user. |
| 2818 | * |
Benjamin Miller | edbc4c4 | 2018-02-22 08:49:21 +0000 | [diff] [blame] | 2819 | * <strong>Note</strong>: This method is not concerned with password quality and will return |
| 2820 | * false if the profile has empty password as a separate challenge. |
Pavel Grafov | c4f87e9 | 2017-10-26 16:34:25 +0100 | [diff] [blame] | 2821 | * |
| 2822 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Tony Mak | 6a97535 | 2018-03-06 11:33:55 +0000 | [diff] [blame] | 2823 | * @throws SecurityException if {@code admin} is not a profile owner of a managed profile. |
Pavel Grafov | c4f87e9 | 2017-10-26 16:34:25 +0100 | [diff] [blame] | 2824 | * @see UserManager#DISALLOW_UNIFIED_PASSWORD |
| 2825 | */ |
| 2826 | public boolean isUsingUnifiedPassword(@NonNull ComponentName admin) { |
Pavel Grafov | 3b27ed0 | 2017-12-18 18:02:47 +0000 | [diff] [blame] | 2827 | throwIfParentInstance("isUsingUnifiedPassword"); |
Pavel Grafov | c4f87e9 | 2017-10-26 16:34:25 +0100 | [diff] [blame] | 2828 | if (mService != null) { |
| 2829 | try { |
| 2830 | return mService.isUsingUnifiedPassword(admin); |
| 2831 | } catch (RemoteException e) { |
| 2832 | throw e.rethrowFromSystemServer(); |
| 2833 | } |
| 2834 | } |
| 2835 | return true; |
| 2836 | } |
| 2837 | |
| 2838 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2839 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2840 | * 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] | 2841 | * requested by the admins of the parent user and its profiles. |
| 2842 | * |
| 2843 | * @param userHandle the userId of the profile to check the password for. |
| 2844 | * @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] | 2845 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2846 | * @hide |
| 2847 | */ |
| 2848 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2849 | if (mService != null) { |
| 2850 | try { |
| 2851 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2852 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2853 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2854 | } |
| 2855 | } |
| 2856 | return false; |
| 2857 | } |
| 2858 | |
| 2859 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2860 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2861 | * successful password entry. |
| 2862 | * <p> |
| 2863 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2864 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2865 | * password attemts for the parent user. |
| 2866 | * <p> |
| 2867 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2868 | * 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] | 2869 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2870 | * @return The number of times user has entered an incorrect password since the last correct |
| 2871 | * password entry. |
| 2872 | * @throws SecurityException if the calling application does not own an active administrator |
| 2873 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2874 | */ |
| 2875 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2876 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2877 | } |
| 2878 | |
| 2879 | /** |
| 2880 | * Retrieve the number of times the given user has failed at entering a |
| 2881 | * password since that last successful password entry. |
| 2882 | * |
| 2883 | * <p>The calling device admin must have requested |
| 2884 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2885 | * not and it is not the system uid, a security exception will be thrown. |
| 2886 | * |
| 2887 | * @hide |
| 2888 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 2889 | @UnsupportedAppUsage |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2890 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2891 | if (mService != null) { |
| 2892 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2893 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2894 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2895 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | return -1; |
| 2899 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2900 | |
| 2901 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2902 | * 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] | 2903 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2904 | * @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] | 2905 | * @hide |
| 2906 | */ |
| 2907 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2908 | if (mService != null) { |
| 2909 | try { |
| 2910 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2911 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2912 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2913 | } |
| 2914 | } |
| 2915 | return false; |
| 2916 | } |
| 2917 | |
| 2918 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2919 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2920 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2921 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2922 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2923 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2924 | * <p> |
| 2925 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2926 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2927 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2928 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2929 | * immediately, and your callback will not be invoked. |
| 2930 | * <p> |
| 2931 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2932 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2933 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2934 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2935 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2936 | * @param num The number of failed password attempts at which point the device or profile will |
| 2937 | * be wiped. |
| 2938 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2939 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2940 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2941 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2942 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2943 | if (mService != null) { |
| 2944 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2945 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2946 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2947 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2951 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2952 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2953 | * 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] | 2954 | * 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] | 2955 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2956 | * not taken into account. |
| 2957 | * |
| 2958 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2959 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2960 | * the value for the parent profile. |
| 2961 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2962 | * @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] | 2963 | * all admins. |
| 2964 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2965 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2966 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | /** @hide per-user version */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 2970 | @UnsupportedAppUsage |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2971 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2972 | if (mService != null) { |
| 2973 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2974 | return mService.getMaximumFailedPasswordsForWipe( |
| 2975 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2976 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2977 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2978 | } |
| 2979 | } |
| 2980 | return 0; |
| 2981 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2982 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2983 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2984 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2985 | * for the given user. So for primary user, it might return the primary or |
| 2986 | * a managed profile. For a secondary user, it would be the same as the |
| 2987 | * user passed in. |
| 2988 | * @hide Used only by Keyguard |
| 2989 | */ |
| 2990 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2991 | if (mService != null) { |
| 2992 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2993 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2994 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2995 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2996 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | return UserHandle.USER_NULL; |
| 3000 | } |
| 3001 | |
| 3002 | /** |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3003 | * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't allow other admins |
| 3004 | * to change the password again until the user has entered it. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 3005 | */ |
| 3006 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3007 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 3008 | /** |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3009 | * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't ask for user |
| 3010 | * credentials on device boot. |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 3011 | * If the flag is set, the device can be booted without asking for user password. |
| 3012 | * The absence of this flag does not change the current boot requirements. This flag |
| 3013 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 3014 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 3015 | * device to factory defaults. |
| 3016 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 3017 | 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] | 3018 | |
| 3019 | /** |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3020 | * Force a new password for device unlock (the password needed to access the entire device) or |
| 3021 | * the work profile challenge on the current user. This takes effect immediately. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3022 | * <p> |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3023 | * <em>For device owner and profile owners targeting SDK level |
| 3024 | * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will |
| 3025 | * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken} |
| 3026 | * instead. </em> |
| 3027 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3028 | * <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] | 3029 | * device admins that are not device owner and not profile owner. |
| 3030 | * 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] | 3031 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 3032 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3033 | * <p> |
| 3034 | * The given password must be sufficient for the current password quality and length constraints |
| 3035 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 3036 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 3037 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 3038 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 3039 | * case the currently active quality will be increased to match. |
| 3040 | * <p> |
| 3041 | * 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] | 3042 | * current password constraints allow it. <em>Note: This will not work in |
| 3043 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 3044 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 3045 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3046 | * <p> |
| 3047 | * The calling device admin must have requested |
| 3048 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 3049 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3050 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 3051 | * @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] | 3052 | * @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] | 3053 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 3054 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 3055 | * current constraints or if the user has not been decrypted yet. |
| 3056 | * @throws SecurityException if the calling application does not own an active administrator |
| 3057 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 3058 | * @throws IllegalStateException if the calling user is locked or has a managed profile. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3059 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 3060 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3061 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3062 | if (mService != null) { |
| 3063 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3064 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3065 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3066 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3067 | } |
| 3068 | } |
| 3069 | return false; |
| 3070 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3071 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3072 | /** |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3073 | * Called by a profile or device owner to provision a token which can later be used to reset the |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 3074 | * device lockscreen password (if called by device owner), or managed profile challenge (if |
| 3075 | * called by profile owner), via {@link #resetPasswordWithToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3076 | * <p> |
| 3077 | * If the user currently has a lockscreen password, the provisioned token will not be |
| 3078 | * immediately usable; it only becomes active after the user performs a confirm credential |
| 3079 | * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 3080 | * If the user has no lockscreen password, the token is activated immediately. In all cases, |
| 3081 | * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}. |
| 3082 | * For security reasons, un-activated tokens are only stored in memory and will be lost once |
| 3083 | * the device reboots. In this case a new token needs to be provisioned again. |
| 3084 | * <p> |
| 3085 | * Once provisioned and activated, the token will remain effective even if the user changes |
| 3086 | * or clears the lockscreen password. |
| 3087 | * <p> |
| 3088 | * <em>This token is highly sensitive and should be treated at the same level as user |
Rubin Xu | f7b036d | 2017-04-05 18:37:07 +0100 | [diff] [blame] | 3089 | * credentials. In particular, NEVER store this token on device in plaintext. Do not store |
| 3090 | * the plaintext token in device-encrypted storage if it will be needed to reset password on |
| 3091 | * file-based encryption devices before user unlocks. Consider carefully how any password token |
| 3092 | * will be stored on your server and who will need access to them. Tokens may be the subject of |
| 3093 | * legal access requests. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3094 | * </em> |
| 3095 | * |
| 3096 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3097 | * @param token a secure token a least 32-byte long, which must be generated by a |
| 3098 | * cryptographically strong random number generator. |
| 3099 | * @return true if the operation is successful, false otherwise. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3100 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3101 | * @throws IllegalArgumentException if the supplied token is invalid. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3102 | */ |
| 3103 | public boolean setResetPasswordToken(ComponentName admin, byte[] token) { |
| 3104 | throwIfParentInstance("setResetPasswordToken"); |
| 3105 | if (mService != null) { |
| 3106 | try { |
| 3107 | return mService.setResetPasswordToken(admin, token); |
| 3108 | } catch (RemoteException e) { |
| 3109 | throw e.rethrowFromSystemServer(); |
| 3110 | } |
| 3111 | } |
| 3112 | return false; |
| 3113 | } |
| 3114 | |
| 3115 | /** |
| 3116 | * Called by a profile or device owner to revoke the current password reset token. |
| 3117 | * |
| 3118 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3119 | * @return true if the operation is successful, false otherwise. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3120 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3121 | */ |
| 3122 | public boolean clearResetPasswordToken(ComponentName admin) { |
| 3123 | throwIfParentInstance("clearResetPasswordToken"); |
| 3124 | if (mService != null) { |
| 3125 | try { |
| 3126 | return mService.clearResetPasswordToken(admin); |
| 3127 | } catch (RemoteException e) { |
| 3128 | throw e.rethrowFromSystemServer(); |
| 3129 | } |
| 3130 | } |
| 3131 | return false; |
| 3132 | } |
| 3133 | |
| 3134 | /** |
| 3135 | * Called by a profile or device owner to check if the current reset password token is active. |
| 3136 | * |
| 3137 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3138 | * @return true if the token is active, false otherwise. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3139 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3140 | * @throws IllegalStateException if no token has been set. |
| 3141 | */ |
| 3142 | public boolean isResetPasswordTokenActive(ComponentName admin) { |
| 3143 | throwIfParentInstance("isResetPasswordTokenActive"); |
| 3144 | if (mService != null) { |
| 3145 | try { |
| 3146 | return mService.isResetPasswordTokenActive(admin); |
| 3147 | } catch (RemoteException e) { |
| 3148 | throw e.rethrowFromSystemServer(); |
| 3149 | } |
| 3150 | } |
| 3151 | return false; |
| 3152 | } |
| 3153 | |
| 3154 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 3155 | * Called by device or profile owner to force set a new device unlock password or a managed |
| 3156 | * profile challenge on current user. This takes effect immediately. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3157 | * <p> |
| 3158 | * Unlike {@link #resetPassword}, this API can change the password even before the user or |
| 3159 | * device is unlocked or decrypted. The supplied token must have been previously provisioned via |
| 3160 | * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}. |
| 3161 | * <p> |
| 3162 | * The given password must be sufficient for the current password quality and length constraints |
| 3163 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 3164 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3165 | * it will be rejected and false returned. Note that the password may be a stronger quality, for |
| 3166 | * example, a password containing alphanumeric characters when the requested quality is only |
| 3167 | * numeric. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3168 | * <p> |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3169 | * Calling with a {@code null} or empty password will clear any existing PIN, pattern or |
| 3170 | * password if the current password constraints allow it. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3171 | * |
| 3172 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3173 | * @param password The new password for the user. {@code null} or empty clears the password. |
| 3174 | * @param token the password reset token previously provisioned by |
| 3175 | * {@link #setResetPasswordToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3176 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3177 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3178 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 3179 | * current constraints. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 3180 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3181 | * @throws IllegalStateException if the provided token is not valid. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 3182 | */ |
| 3183 | public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password, |
| 3184 | byte[] token, int flags) { |
| 3185 | throwIfParentInstance("resetPassword"); |
| 3186 | if (mService != null) { |
| 3187 | try { |
| 3188 | return mService.resetPasswordWithToken(admin, password, token, flags); |
| 3189 | } catch (RemoteException e) { |
| 3190 | throw e.rethrowFromSystemServer(); |
| 3191 | } |
| 3192 | } |
| 3193 | return false; |
| 3194 | } |
| 3195 | |
| 3196 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3197 | * Called by an application that is administering the device to set the maximum time for user |
| 3198 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 3199 | * effect immediately. |
| 3200 | * <p> |
| 3201 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3202 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3203 | * <p> |
| 3204 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3205 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3206 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3207 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 3208 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3209 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 3210 | * is no restriction. |
| 3211 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 3212 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3213 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3214 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3215 | if (mService != null) { |
| 3216 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3217 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3218 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3219 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3223 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3224 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3225 | * 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] | 3226 | * 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] | 3227 | * a separate challenge are not taken into account. |
| 3228 | * |
| 3229 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3230 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3231 | * restrictions on the parent profile. |
| 3232 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3233 | * @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] | 3234 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 3235 | * @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] | 3236 | * 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] | 3237 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3238 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3239 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | /** @hide per-user version */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3243 | @UnsupportedAppUsage |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3244 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3245 | if (mService != null) { |
| 3246 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3247 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3248 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3249 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3250 | } |
| 3251 | } |
| 3252 | return 0; |
| 3253 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3254 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3255 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3256 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 3257 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 3258 | * authentication method like password, pin or pattern. |
| 3259 | * |
| 3260 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 3261 | * specified timeout each time it has been successfully used. |
| 3262 | * |
| 3263 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 3264 | * |
| 3265 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 3266 | * |
| 3267 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 3268 | * a {@link SecurityException} will be thrown. |
| 3269 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 3270 | * <p>The calling device admin can verify the value it has set by calling |
| 3271 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 3272 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3273 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3274 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3275 | * profile. |
| 3276 | * |
| 3277 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3278 | * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock |
| 3279 | * with strong authentication method. A value of 0 means the admin is not participating |
| 3280 | * in controlling the timeout. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 3281 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 3282 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 3283 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 3284 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3285 | * |
| 3286 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3287 | */ |
| 3288 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 3289 | long timeoutMs) { |
| 3290 | if (mService != null) { |
| 3291 | try { |
| 3292 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 3293 | } catch (RemoteException e) { |
| 3294 | throw e.rethrowFromSystemServer(); |
| 3295 | } |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | /** |
| 3300 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 3301 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 3302 | * After the returned timeout the user is required to use strong authentication method. |
| 3303 | * |
| 3304 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3305 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3306 | * restrictions on the parent profile. |
| 3307 | * |
| 3308 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 3309 | * across all participating admins. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3310 | * @return The timeout in milliseconds or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3311 | */ |
| 3312 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 3313 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 3314 | } |
| 3315 | |
| 3316 | /** @hide per-user version */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3317 | @UnsupportedAppUsage |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3318 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 3319 | if (mService != null) { |
| 3320 | try { |
| 3321 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 3322 | } catch (RemoteException e) { |
| 3323 | throw e.rethrowFromSystemServer(); |
| 3324 | } |
| 3325 | } |
| 3326 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 3327 | } |
| 3328 | |
| 3329 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3330 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 3331 | * keyring. The user's credential will need to be entered again in order to derive the |
| 3332 | * credential encryption key that will be stored back in the keyring for future use. |
| 3333 | * <p> |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3334 | * This flag can only be used by a profile owner when locking a managed profile when |
| 3335 | * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3336 | * <p> |
| 3337 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 3338 | * until they are next run to perform further actions. |
| 3339 | */ |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3340 | public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1; |
| 3341 | |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3342 | /** @hide */ |
| 3343 | @Retention(RetentionPolicy.SOURCE) |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 3344 | @IntDef(flag = true, prefix = { "FLAG_EVICT_" }, value = { |
| 3345 | FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY |
| 3346 | }) |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3347 | public @interface LockNowFlag {} |
| 3348 | |
| 3349 | /** |
| 3350 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3351 | * this call. |
| 3352 | * <p> |
| 3353 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3354 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3355 | * <p> |
| 3356 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3357 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 3358 | * <p> |
| 3359 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 3360 | * |
| 3361 | * @throws SecurityException if the calling application does not own an active administrator |
| 3362 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3363 | */ |
| 3364 | public void lockNow() { |
| 3365 | lockNow(0); |
| 3366 | } |
| 3367 | |
| 3368 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3369 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3370 | * this call. |
| 3371 | * <p> |
| 3372 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3373 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3374 | * <p> |
| 3375 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3376 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3377 | * |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3378 | * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3379 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3380 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3381 | * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application |
| 3382 | * that is not a profile |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3383 | * owner of a managed profile. |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3384 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is |
| 3385 | * passed when locking the parent profile. |
| 3386 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} |
| 3387 | * flag is passed when {@link #getStorageEncryptionStatus} does not return |
| 3388 | * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3389 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3390 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3391 | if (mService != null) { |
| 3392 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3393 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3394 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3395 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3396 | } |
| 3397 | } |
| 3398 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3399 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3400 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3401 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3402 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3403 | */ |
| 3404 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 3405 | |
| 3406 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3407 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 3408 | * data. |
| 3409 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 3410 | * <p>This flag may only be set by device owner admins; if it is set by |
| 3411 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3412 | */ |
| 3413 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 3414 | |
| 3415 | /** |
yinxu | f4f9cec | 2017-06-19 10:28:19 -0700 | [diff] [blame] | 3416 | * Flag for {@link #wipeData(int)}: also erase the device's eUICC data. |
yinxu | f4f9cec | 2017-06-19 10:28:19 -0700 | [diff] [blame] | 3417 | */ |
| 3418 | public static final int WIPE_EUICC = 0x0004; |
| 3419 | |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3420 | |
yinxu | f4f9cec | 2017-06-19 10:28:19 -0700 | [diff] [blame] | 3421 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 3422 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3423 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 3424 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 3425 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3426 | * <p> |
| 3427 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3428 | * 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] | 3429 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3430 | * @param flags Bit mask of additional options: currently supported flags are |
| 3431 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3432 | * @throws SecurityException if the calling application does not own an active administrator |
| 3433 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3434 | */ |
| 3435 | public void wipeData(int flags) { |
yuemingw | 2280019 | 2017-11-07 15:19:45 +0000 | [diff] [blame] | 3436 | throwIfParentInstance("wipeData"); |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3437 | final String wipeReasonForUser = mContext.getString( |
| 3438 | R.string.work_profile_deleted_description_dpm_wipe); |
| 3439 | wipeDataInternal(flags, wipeReasonForUser); |
| 3440 | } |
| 3441 | |
| 3442 | /** |
| 3443 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3444 | * other users will remain unaffected, the provided reason for wiping data can be shown to |
| 3445 | * user. Calling from the primary user will cause the device to reboot, erasing all device data |
| 3446 | * - including all the secondary users and their data - while booting up. In this case, we don't |
| 3447 | * show the reason to the user since the device would be factory reset. |
| 3448 | * <p> |
| 3449 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3450 | * be able to call this method; if it has not, a security exception will be thrown. |
| 3451 | * |
| 3452 | * @param flags Bit mask of additional options: currently supported flags are |
| 3453 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3454 | * @param reason a string that contains the reason for wiping data, which can be |
| 3455 | * presented to the user. |
| 3456 | * @throws SecurityException if the calling application does not own an active administrator |
| 3457 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
| 3458 | * @throws IllegalArgumentException if the input reason string is null or empty. |
| 3459 | */ |
yuemingw | 8227e5b | 2018-02-22 17:29:10 +0000 | [diff] [blame] | 3460 | public void wipeData(int flags, @NonNull CharSequence reason) { |
| 3461 | throwIfParentInstance("wipeData"); |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3462 | Preconditions.checkNotNull(reason, "CharSequence is null"); |
| 3463 | wipeDataInternal(flags, reason.toString()); |
| 3464 | } |
| 3465 | |
| 3466 | /** |
| 3467 | * Internal function for both {@link #wipeData(int)} and |
yuemingw | 8227e5b | 2018-02-22 17:29:10 +0000 | [diff] [blame] | 3468 | * {@link #wipeData(int, CharSequence)} to call. |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3469 | * |
| 3470 | * @see #wipeData(int) |
yuemingw | 8227e5b | 2018-02-22 17:29:10 +0000 | [diff] [blame] | 3471 | * @see #wipeData(int, CharSequence) |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3472 | * @hide |
| 3473 | */ |
| 3474 | private void wipeDataInternal(int flags, @NonNull String wipeReasonForUser) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3475 | if (mService != null) { |
| 3476 | try { |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3477 | mService.wipeDataWithReason(flags, wipeReasonForUser); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3478 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3479 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3480 | } |
| 3481 | } |
| 3482 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3483 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3484 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3485 | * Called by an application that is administering the device to set the |
| 3486 | * global proxy and exclusion list. |
| 3487 | * <p> |
| 3488 | * The calling device admin must have requested |
| 3489 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3490 | * this method; if it has not, a security exception will be thrown. |
| 3491 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3492 | * 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] | 3493 | * 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] | 3494 | * be returned. |
| 3495 | * The method can be called repeatedly by the device admin alrady setting the |
| 3496 | * proxy to update the proxy and exclusion list. |
| 3497 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3498 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3499 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3500 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3501 | * @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] | 3502 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3503 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3504 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3505 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3506 | @UnsupportedAppUsage |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3507 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3508 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3509 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3510 | if (proxySpec == null) { |
| 3511 | throw new NullPointerException(); |
| 3512 | } |
| 3513 | if (mService != null) { |
| 3514 | try { |
| 3515 | String hostSpec; |
| 3516 | String exclSpec; |
| 3517 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3518 | hostSpec = null; |
| 3519 | exclSpec = null; |
| 3520 | } else { |
| 3521 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3522 | throw new IllegalArgumentException(); |
| 3523 | } |
| 3524 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3525 | String hostName = sa.getHostName(); |
| 3526 | int port = sa.getPort(); |
| 3527 | StringBuilder hostBuilder = new StringBuilder(); |
| 3528 | hostSpec = hostBuilder.append(hostName) |
| 3529 | .append(":").append(Integer.toString(port)).toString(); |
| 3530 | if (exclusionList == null) { |
| 3531 | exclSpec = ""; |
| 3532 | } else { |
| 3533 | StringBuilder listBuilder = new StringBuilder(); |
| 3534 | boolean firstDomain = true; |
| 3535 | for (String exclDomain : exclusionList) { |
| 3536 | if (!firstDomain) { |
| 3537 | listBuilder = listBuilder.append(","); |
| 3538 | } else { |
| 3539 | firstDomain = false; |
| 3540 | } |
| 3541 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3542 | } |
| 3543 | exclSpec = listBuilder.toString(); |
| 3544 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3545 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3546 | != android.net.Proxy.PROXY_VALID) |
| 3547 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3548 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3549 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3550 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3551 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3552 | } |
| 3553 | } |
| 3554 | return null; |
| 3555 | } |
| 3556 | |
| 3557 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3558 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3559 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3560 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3561 | * proxy is not accessible, you may break HTTP using this. |
| 3562 | * <p> |
| 3563 | * This method requires the caller to be the device owner. |
| 3564 | * <p> |
| 3565 | * 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] | 3566 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3567 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3568 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3569 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3570 | * {@code null} value will clear the global HTTP proxy. |
| 3571 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3572 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3573 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3574 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3575 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3576 | if (mService != null) { |
| 3577 | try { |
| 3578 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3579 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3580 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3581 | } |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3586 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3587 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3588 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3589 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3590 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3591 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3592 | if (mService != null) { |
| 3593 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3594 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3595 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3596 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | return null; |
| 3600 | } |
| 3601 | |
| 3602 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3603 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3604 | * indicating that encryption is not supported. |
| 3605 | */ |
| 3606 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3607 | |
| 3608 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3609 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3610 | * indicating that encryption is supported, but is not currently active. |
| 3611 | */ |
| 3612 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3613 | |
| 3614 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3615 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3616 | * indicating that encryption is not currently active, but is currently |
| 3617 | * being activated. This is only reported by devices that support |
| 3618 | * encryption of data and only when the storage is currently |
| 3619 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3620 | * to become encrypted will never return this value. |
| 3621 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3622 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3623 | |
| 3624 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3625 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3626 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3627 | * <p> |
| 3628 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3629 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3630 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3631 | |
| 3632 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3633 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3634 | * indicating that encryption is active, but an encryption key has not |
| 3635 | * been set by the user. |
| 3636 | */ |
| 3637 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3638 | |
| 3639 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3640 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3641 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3642 | * <p> |
| 3643 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3644 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3645 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3646 | */ |
| 3647 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3648 | |
| 3649 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3650 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3651 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3652 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3653 | * to check encryption status. However, on some devices this activity may never return, as |
| 3654 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3655 | */ |
| 3656 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3657 | public static final String ACTION_START_ENCRYPTION |
| 3658 | = "android.app.action.START_ENCRYPTION"; |
Alex Chau | b6a9f94 | 2017-11-07 11:28:56 +0800 | [diff] [blame] | 3659 | |
| 3660 | /** |
| 3661 | * Broadcast action: notify managed provisioning that new managed user is created. |
| 3662 | * |
| 3663 | * @hide |
| 3664 | */ |
| 3665 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 3666 | public static final String ACTION_MANAGED_USER_CREATED = |
| 3667 | "android.app.action.MANAGED_USER_CREATED"; |
| 3668 | |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3669 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3670 | * Widgets are enabled in keyguard |
| 3671 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3672 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3673 | |
| 3674 | /** |
Rubin Xu | 4b2f7aa | 2018-03-02 15:41:53 +0000 | [diff] [blame] | 3675 | * Disable all keyguard widgets. Has no effect starting from |
| 3676 | * {@link android.os.Build.VERSION_CODES#LOLLIPOP} since keyguard widget is only supported |
| 3677 | * on Android versions lower than 5.0. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3678 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3679 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3680 | |
| 3681 | /** |
| 3682 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3683 | */ |
| 3684 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3685 | |
| 3686 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3687 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3688 | */ |
| 3689 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3690 | |
| 3691 | /** |
| 3692 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3693 | */ |
| 3694 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3695 | |
| 3696 | /** |
Rubin Xu | 50ac241 | 2018-03-02 15:25:28 +0000 | [diff] [blame] | 3697 | * Disable trust agents on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3698 | * By setting this flag alone, all trust agents are disabled. If the admin then wants to |
| 3699 | * whitelist specific features of some trust agent, {@link #setTrustAgentConfiguration} can be |
| 3700 | * used in conjuction to set trust-agent-specific configurations. |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3701 | */ |
| 3702 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3703 | |
| 3704 | /** |
Vishwath Mohan | cf87df1 | 2018-03-20 22:57:17 -0700 | [diff] [blame] | 3705 | * Disable fingerprint authentication on keyguard secure screens (e.g. PIN/Pattern/Password). |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3706 | */ |
| 3707 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3708 | |
| 3709 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3710 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3711 | */ |
| 3712 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3713 | |
| 3714 | /** |
Vishwath Mohan | cf87df1 | 2018-03-20 22:57:17 -0700 | [diff] [blame] | 3715 | * Disable face authentication on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3716 | */ |
| 3717 | public static final int KEYGUARD_DISABLE_FACE = 1 << 7; |
| 3718 | |
| 3719 | /** |
| 3720 | * Disable iris authentication on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3721 | */ |
| 3722 | public static final int KEYGUARD_DISABLE_IRIS = 1 << 8; |
| 3723 | |
| 3724 | /** |
| 3725 | * Disable all biometric authentication on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3726 | */ |
| 3727 | public static final int KEYGUARD_DISABLE_BIOMETRICS = |
| 3728 | DevicePolicyManager.KEYGUARD_DISABLE_FACE |
| 3729 | | DevicePolicyManager.KEYGUARD_DISABLE_IRIS |
| 3730 | | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT; |
| 3731 | |
| 3732 | |
| 3733 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3734 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3735 | */ |
| 3736 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3737 | |
| 3738 | /** |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3739 | * Keyguard features that when set on a managed profile that doesn't have its own challenge will |
| 3740 | * affect the profile's parent user. These can also be set on the managed profile's parent |
| 3741 | * {@link DevicePolicyManager} instance. |
| 3742 | * |
| 3743 | * @hide |
| 3744 | */ |
| 3745 | public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER = |
| 3746 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS |
Rubin Xu | c418d5a | 2018-05-02 12:18:18 +0100 | [diff] [blame] | 3747 | | DevicePolicyManager.KEYGUARD_DISABLE_BIOMETRICS; |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3748 | |
| 3749 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3750 | * Called by an application that is administering the device to request that the storage system |
Alex Kershaw | 61ec825 | 2018-03-16 14:31:04 +0000 | [diff] [blame] | 3751 | * be encrypted. Does nothing if the caller is on a secondary user or a managed profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3752 | * <p> |
| 3753 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3754 | * supported setting will always be used. If any device administrator requests device |
| 3755 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3756 | * 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] | 3757 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3758 | * <p> |
| 3759 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3760 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3761 | * control the encryption of any other storage areas. There is one exception: If |
| 3762 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3763 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3764 | * written to disk within the encrypted storage area. |
| 3765 | * <p> |
| 3766 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3767 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3768 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3769 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3770 | * |
| 3771 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3772 | * @param encrypt true to request encryption, false to release any previous request |
Alex Kershaw | 61ec825 | 2018-03-16 14:31:04 +0000 | [diff] [blame] | 3773 | * @return the new total request status (for all active admins), or {@link |
| 3774 | * DevicePolicyManager#ENCRYPTION_STATUS_UNSUPPORTED} if called for a non-system user. |
| 3775 | * Will be one of {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link |
| 3776 | * #ENCRYPTION_STATUS_INACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value |
| 3777 | * of the requests; use {@link #getStorageEncryptionStatus()} to query the actual device |
| 3778 | * state. |
| 3779 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3780 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3781 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3782 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3783 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3784 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3785 | if (mService != null) { |
| 3786 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3787 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3788 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3789 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3790 | } |
| 3791 | } |
| 3792 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3793 | } |
| 3794 | |
| 3795 | /** |
| 3796 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3797 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3798 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3799 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3800 | * this will return the requested encryption setting as an aggregate of all active |
| 3801 | * administrators. |
| 3802 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3803 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3804 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3805 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3806 | if (mService != null) { |
| 3807 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3808 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3809 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3810 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3811 | } |
| 3812 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3813 | return false; |
| 3814 | } |
| 3815 | |
| 3816 | /** |
| 3817 | * Called by an application that is administering the device to |
| 3818 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3819 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3820 | * Depending on the returned status code, the caller may proceed in different |
| 3821 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3822 | * storage system does not support encryption. If the |
| 3823 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3824 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3825 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3826 | * 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] | 3827 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3828 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3829 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3830 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3831 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3832 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3833 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3834 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3835 | */ |
| 3836 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3837 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3838 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | /** @hide per-user version */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3842 | @UnsupportedAppUsage |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3843 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3844 | if (mService != null) { |
| 3845 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3846 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3847 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3848 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3849 | } |
| 3850 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3851 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3852 | } |
| 3853 | |
| 3854 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3855 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3856 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3857 | * keep the certificate on the device. |
| 3858 | * |
| 3859 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3860 | * this certificate. |
| 3861 | * |
| 3862 | * @hide |
| 3863 | */ |
| 3864 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3865 | if (mService != null) { |
| 3866 | try { |
| 3867 | return mService.approveCaCert(alias, userHandle, approval); |
| 3868 | } catch (RemoteException e) { |
| 3869 | throw e.rethrowFromSystemServer(); |
| 3870 | } |
| 3871 | } |
| 3872 | return false; |
| 3873 | } |
| 3874 | |
| 3875 | /** |
| 3876 | * Check whether a CA certificate has been approved by the device user. |
| 3877 | * |
| 3878 | * @hide |
| 3879 | */ |
| 3880 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3881 | if (mService != null) { |
| 3882 | try { |
| 3883 | return mService.isCaCertApproved(alias, userHandle); |
| 3884 | } catch (RemoteException e) { |
| 3885 | throw e.rethrowFromSystemServer(); |
| 3886 | } |
| 3887 | } |
| 3888 | return false; |
| 3889 | } |
| 3890 | |
| 3891 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3892 | * Installs the given certificate as a user CA. |
Benjamin Miller | 8a12c12 | 2017-04-04 12:38:24 +0200 | [diff] [blame] | 3893 | * <p> |
| 3894 | * Inserted user CAs aren't automatically trusted by apps in Android 7.0 (API level 24) and |
| 3895 | * higher. App developers can change the default behavior for an app by adding a |
| 3896 | * <a href="{@docRoot}training/articles/security-config.html">Security Configuration |
| 3897 | * File</a> to the app manifest file. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3898 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3899 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3900 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3901 | * security exception will be thrown. |
| 3902 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3903 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3904 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3905 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3906 | * |
| 3907 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3908 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3909 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3910 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3911 | * @see #setDelegatedScopes |
| 3912 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3913 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3914 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3915 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3916 | if (mService != null) { |
| 3917 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3918 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3919 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3920 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3921 | } |
| 3922 | } |
| 3923 | return false; |
| 3924 | } |
| 3925 | |
| 3926 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3927 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3928 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3929 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3930 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3931 | * security exception will be thrown. |
| 3932 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3933 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3934 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3935 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3936 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3937 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3938 | * @see #setDelegatedScopes |
| 3939 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3940 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3941 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3942 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3943 | if (mService != null) { |
| 3944 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3945 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3946 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3947 | } catch (CertificateException e) { |
| 3948 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3949 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3950 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3951 | } |
| 3952 | } |
| 3953 | } |
| 3954 | |
| 3955 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3956 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3957 | * If a user has installed any certificates by other means than device policy these will be |
| 3958 | * included too. |
| 3959 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3960 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3961 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3962 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3963 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3964 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3965 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3966 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3967 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3968 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3969 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3970 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3971 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3972 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3973 | for (String alias : certStore.userAliases()) { |
| 3974 | try { |
| 3975 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3976 | } catch (CertificateException ce) { |
| 3977 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3978 | } |
| 3979 | } |
| 3980 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3981 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3982 | } |
| 3983 | } |
| 3984 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3988 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3989 | * means other than device policy will also be removed, except for system CA certificates. |
| 3990 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3991 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3992 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3993 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3994 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3995 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3996 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3997 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3998 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3999 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4000 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 4001 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 4002 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4003 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 4004 | } |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | /** |
| 4009 | * Returns whether this certificate is installed as a trusted CA. |
| 4010 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4011 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4012 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 4013 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4014 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 4015 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 4016 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4017 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4018 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 4019 | if (mService != null) { |
| 4020 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4021 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 4022 | return getCaCertAlias(certBuffer) != null; |
| 4023 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4024 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 4025 | } catch (CertificateException ce) { |
| 4026 | Log.w(TAG, "Could not parse certificate", ce); |
| 4027 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 4028 | } |
| 4029 | return false; |
| 4030 | } |
| 4031 | |
| 4032 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4033 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 4034 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 4035 | * the certificate and use the private key, given direct user approval. |
| 4036 | * |
| 4037 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 4038 | * direct user approval. This is for security - should a certificate installer become |
| 4039 | * compromised, certificates it had already installed will be protected. |
| 4040 | * |
| 4041 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 4042 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 4043 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4044 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4045 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 4046 | * @param privKey The private key to install. |
| 4047 | * @param cert The certificate to install. |
| 4048 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 4049 | * with that alias already exists, it will be overwritten. |
| 4050 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4051 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 4052 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4053 | * @see #setDelegatedScopes |
| 4054 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 4055 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4056 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 4057 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 4058 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /** |
| 4062 | * 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] | 4063 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 4064 | * profile will be able to access the certificate chain and use the private key, given direct |
| 4065 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4066 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 4067 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 4068 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 4069 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4070 | * |
| 4071 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 4072 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4073 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 4074 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 4075 | * certificate and include the chain of trust in order. This will be returned by |
| 4076 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4077 | * @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] | 4078 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4079 | * @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] | 4080 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 4081 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4082 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4083 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 4084 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 4085 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4086 | * @see #setDelegatedScopes |
| 4087 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 4088 | */ |
| 4089 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 4090 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Eran Messeri | f15d4f4 | 2018-03-23 13:32:17 +0000 | [diff] [blame] | 4091 | int flags = INSTALLKEY_SET_USER_SELECTABLE; |
| 4092 | if (requestAccess) { |
| 4093 | flags |= INSTALLKEY_REQUEST_CREDENTIALS_ACCESS; |
| 4094 | } |
| 4095 | return installKeyPair(admin, privKey, certs, alias, flags); |
Eran Messeri | 19d1904 | 2017-11-20 12:48:52 +0000 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | /** |
| 4099 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 4100 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 4101 | * profile will be able to access the certificate chain and use the private key, given direct |
| 4102 | * user approval (if the user is allowed to select the private key). |
| 4103 | * |
| 4104 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 4105 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 4106 | * necessary since it opens up additional security vulnerabilities. |
| 4107 | * |
Benjamin Miller | 8040fd1 | 2018-04-16 15:52:15 +0000 | [diff] [blame] | 4108 | * <p>Include {@link #INSTALLKEY_SET_USER_SELECTABLE} in the {@code flags} argument to allow |
| 4109 | * the user to select the key from a dialog. |
Eran Messeri | 19d1904 | 2017-11-20 12:48:52 +0000 | [diff] [blame] | 4110 | * |
| 4111 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4112 | * {@code null} if calling from a delegated certificate installer. |
| 4113 | * @param privKey The private key to install. |
| 4114 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 4115 | * certificate and include the chain of trust in order. This will be returned by |
| 4116 | * {@link android.security.KeyChain#getCertificateChain}. |
| 4117 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 4118 | * with that alias already exists, it will be overwritten. |
Eran Messeri | f15d4f4 | 2018-03-23 13:32:17 +0000 | [diff] [blame] | 4119 | * @param flags Flags to request that the calling app be granted access to the credentials |
| 4120 | * and set the key to be user-selectable. See {@link #INSTALLKEY_SET_USER_SELECTABLE} and |
| 4121 | * {@link #INSTALLKEY_REQUEST_CREDENTIALS_ACCESS}. |
Eran Messeri | 19d1904 | 2017-11-20 12:48:52 +0000 | [diff] [blame] | 4122 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 4123 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 4124 | * owner. |
| 4125 | * @see android.security.KeyChain#getCertificateChain |
| 4126 | * @see #setDelegatedScopes |
| 4127 | * @see #DELEGATION_CERT_INSTALL |
| 4128 | */ |
| 4129 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Eran Messeri | f15d4f4 | 2018-03-23 13:32:17 +0000 | [diff] [blame] | 4130 | @NonNull Certificate[] certs, @NonNull String alias, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4131 | throwIfParentInstance("installKeyPair"); |
Eran Messeri | f15d4f4 | 2018-03-23 13:32:17 +0000 | [diff] [blame] | 4132 | boolean requestAccess = (flags & INSTALLKEY_REQUEST_CREDENTIALS_ACCESS) |
| 4133 | == INSTALLKEY_REQUEST_CREDENTIALS_ACCESS; |
| 4134 | boolean isUserSelectable = (flags & INSTALLKEY_SET_USER_SELECTABLE) |
| 4135 | == INSTALLKEY_SET_USER_SELECTABLE; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 4136 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 4137 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 4138 | byte[] pemChain = null; |
| 4139 | if (certs.length > 1) { |
| 4140 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 4141 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 4142 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 4143 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4144 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
Eran Messeri | 19d1904 | 2017-11-20 12:48:52 +0000 | [diff] [blame] | 4145 | pemChain, alias, requestAccess, isUserSelectable); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 4146 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4147 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 4148 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 4149 | Log.w(TAG, "Failed to obtain private key material", e); |
| 4150 | } catch (CertificateException | IOException e) { |
| 4151 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 4152 | } |
| 4153 | return false; |
| 4154 | } |
| 4155 | |
| 4156 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 4157 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 4158 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4159 | * |
| 4160 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 4161 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4162 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 4163 | * @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] | 4164 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 4165 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4166 | * @see #setDelegatedScopes |
| 4167 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4168 | */ |
| 4169 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4170 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4171 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4172 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4173 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4174 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4175 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | /** |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4179 | * Called by a device or profile owner, or delegated certificate installer, to generate a |
| 4180 | * new private/public key pair. If the device supports key generation via secure hardware, |
| 4181 | * this method is useful for creating a key in KeyChain that never left the secure hardware. |
| 4182 | * |
| 4183 | * Access to the key is controlled the same way as in {@link #installKeyPair}. |
| 4184 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4185 | * {@code null} if calling from a delegated certificate installer. |
| 4186 | * @param algorithm The key generation algorithm, see {@link java.security.KeyPairGenerator}. |
| 4187 | * @param keySpec Specification of the key to generate, see |
| 4188 | * {@link java.security.KeyPairGenerator}. |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 4189 | * @param idAttestationFlags A bitmask of all the identifiers that should be included in the |
| 4190 | * attestation record ({@code ID_TYPE_BASE_INFO}, {@code ID_TYPE_SERIAL}, |
| 4191 | * {@code ID_TYPE_IMEI} and {@code ID_TYPE_MEID}), or {@code 0} if no device |
| 4192 | * identification is required in the attestation record. |
| 4193 | * Device owner, profile owner and their delegated certificate installer can use |
| 4194 | * {@link #ID_TYPE_BASE_INFO} to request inclusion of the general device information |
| 4195 | * including manufacturer, model, brand, device and product in the attestation record. |
| 4196 | * Only device owner and their delegated certificate installer can use |
| 4197 | * {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID} to request |
| 4198 | * unique device identifiers to be attested. |
| 4199 | * <p> |
| 4200 | * If any of {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID} |
| 4201 | * is set, it is implicitly assumed that {@link #ID_TYPE_BASE_INFO} is also set. |
| 4202 | * <p> |
| 4203 | * If any flag is specified, then an attestation challenge must be included in the |
| 4204 | * {@code keySpec}. |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4205 | * @return A non-null {@code AttestedKeyPair} if the key generation succeeded, null otherwise. |
| 4206 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 4207 | * owner. If Device ID attestation is requested (using {@link #ID_TYPE_SERIAL}, |
| 4208 | * {@link #ID_TYPE_IMEI} or {@link #ID_TYPE_MEID}), the caller must be the Device Owner |
| 4209 | * or the Certificate Installer delegate. |
| 4210 | * @throws IllegalArgumentException if the alias in {@code keySpec} is empty, if the |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4211 | * algorithm specification in {@code keySpec} is not {@code RSAKeyGenParameterSpec} |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 4212 | * or {@code ECGenParameterSpec}, or if Device ID attestation was requested but the |
| 4213 | * {@code keySpec} does not contain an attestation challenge. |
Eran Messeri | 6169239 | 2018-03-26 16:43:14 +0100 | [diff] [blame] | 4214 | * @throws UnsupportedOperationException if Device ID attestation was requested but the |
| 4215 | * underlying hardware does not support it. |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 4216 | * @see KeyGenParameterSpec.Builder#setAttestationChallenge(byte[]) |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4217 | */ |
| 4218 | public AttestedKeyPair generateKeyPair(@Nullable ComponentName admin, |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 4219 | @NonNull String algorithm, @NonNull KeyGenParameterSpec keySpec, |
| 4220 | @AttestationIdType int idAttestationFlags) { |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4221 | throwIfParentInstance("generateKeyPair"); |
| 4222 | try { |
| 4223 | final ParcelableKeyGenParameterSpec parcelableSpec = |
| 4224 | new ParcelableKeyGenParameterSpec(keySpec); |
Eran Messeri | a173064 | 2017-12-11 17:48:47 +0000 | [diff] [blame] | 4225 | KeymasterCertificateChain attestationChain = new KeymasterCertificateChain(); |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 4226 | |
| 4227 | // Translate ID attestation flags to values used by AttestationUtils |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4228 | final boolean success = mService.generateKeyPair( |
Eran Messeri | 94d5676 | 2017-12-21 20:50:54 +0000 | [diff] [blame] | 4229 | admin, mContext.getPackageName(), algorithm, parcelableSpec, |
| 4230 | idAttestationFlags, attestationChain); |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4231 | if (!success) { |
| 4232 | Log.e(TAG, "Error generating key via DevicePolicyManagerService."); |
| 4233 | return null; |
| 4234 | } |
| 4235 | |
Eran Messeri | a173064 | 2017-12-11 17:48:47 +0000 | [diff] [blame] | 4236 | final String alias = keySpec.getKeystoreAlias(); |
| 4237 | final KeyPair keyPair = KeyChain.getKeyPair(mContext, alias); |
| 4238 | Certificate[] outputChain = null; |
| 4239 | try { |
| 4240 | if (AttestationUtils.isChainValid(attestationChain)) { |
| 4241 | outputChain = AttestationUtils.parseCertificateChain(attestationChain); |
| 4242 | } |
| 4243 | } catch (KeyAttestationException e) { |
| 4244 | Log.e(TAG, "Error parsing attestation chain for alias " + alias, e); |
| 4245 | mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
| 4246 | return null; |
| 4247 | } |
| 4248 | return new AttestedKeyPair(keyPair, outputChain); |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4249 | } catch (RemoteException e) { |
| 4250 | throw e.rethrowFromSystemServer(); |
| 4251 | } catch (KeyChainException e) { |
| 4252 | Log.w(TAG, "Failed to generate key", e); |
| 4253 | } catch (InterruptedException e) { |
| 4254 | Log.w(TAG, "Interrupted while generating key", e); |
| 4255 | Thread.currentThread().interrupt(); |
| 4256 | } |
| 4257 | return null; |
| 4258 | } |
| 4259 | |
Eran Messeri | adaf68c | 2018-03-27 19:34:03 +0100 | [diff] [blame] | 4260 | /** |
| 4261 | * Returns {@code true} if the device supports attestation of device identifiers in addition |
| 4262 | * to key attestation. |
| 4263 | * @return {@code true} if Device ID attestation is supported. |
| 4264 | */ |
| 4265 | public boolean isDeviceIdAttestationSupported() { |
| 4266 | PackageManager pm = mContext.getPackageManager(); |
| 4267 | return pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ID_ATTESTATION); |
| 4268 | } |
Eran Messeri | ecf0f22 | 2017-12-11 12:32:13 +0000 | [diff] [blame] | 4269 | |
| 4270 | /** |
| 4271 | * Called by a device or profile owner, or delegated certificate installer, to associate |
| 4272 | * certificates with a key pair that was generated using {@link #generateKeyPair}, and |
| 4273 | * set whether the key is available for the user to choose in the certificate selection |
| 4274 | * prompt. |
| 4275 | * |
| 4276 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4277 | * {@code null} if calling from a delegated certificate installer. |
| 4278 | * @param alias The private key alias under which to install the certificate. The {@code alias} |
| 4279 | * should denote an existing private key. If a certificate with that alias already |
| 4280 | * exists, it will be overwritten. |
| 4281 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 4282 | * certificate and include the chain of trust in order. This will be returned by |
| 4283 | * {@link android.security.KeyChain#getCertificateChain}. |
| 4284 | * @param isUserSelectable {@code true} to indicate that a user can select this key via the |
| 4285 | * certificate selection prompt, {@code false} to indicate that this key can only be |
| 4286 | * granted access by implementing |
| 4287 | * {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias}. |
| 4288 | * @return {@code true} if the provided {@code alias} exists and the certificates has been |
| 4289 | * successfully associated with it, {@code false} otherwise. |
| 4290 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 4291 | * owner, or {@code admin} is null but the calling application is not a delegated |
| 4292 | * certificate installer. |
| 4293 | */ |
| 4294 | public boolean setKeyPairCertificate(@Nullable ComponentName admin, |
| 4295 | @NonNull String alias, @NonNull List<Certificate> certs, boolean isUserSelectable) { |
| 4296 | throwIfParentInstance("setKeyPairCertificate"); |
| 4297 | try { |
| 4298 | final byte[] pemCert = Credentials.convertToPem(certs.get(0)); |
| 4299 | byte[] pemChain = null; |
| 4300 | if (certs.size() > 1) { |
| 4301 | pemChain = Credentials.convertToPem( |
| 4302 | certs.subList(1, certs.size()).toArray(new Certificate[0])); |
| 4303 | } |
| 4304 | return mService.setKeyPairCertificate(admin, mContext.getPackageName(), alias, pemCert, |
| 4305 | pemChain, isUserSelectable); |
| 4306 | } catch (RemoteException e) { |
| 4307 | throw e.rethrowFromSystemServer(); |
| 4308 | } catch (CertificateException | IOException e) { |
| 4309 | Log.w(TAG, "Could not pem-encode certificate", e); |
| 4310 | } |
| 4311 | return false; |
| 4312 | } |
| 4313 | |
| 4314 | |
Eran Messeri | 852c8f1 | 2017-11-15 05:55:52 +0000 | [diff] [blame] | 4315 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4316 | * @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] | 4317 | * doesn't exist. |
| 4318 | */ |
| 4319 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 4320 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 4321 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 4322 | new ByteArrayInputStream(certBuffer)); |
| 4323 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 4324 | } |
| 4325 | |
| 4326 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4327 | * 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] | 4328 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4329 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 4330 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4331 | * <p> |
| 4332 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 4333 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 4334 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4335 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4336 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 4337 | * 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] | 4338 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 4339 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4340 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4341 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4342 | * @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] | 4343 | * access. If {@code null} is given the current package will be cleared. |
| 4344 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4345 | * |
| 4346 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 4347 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4348 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4349 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4350 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 4351 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4352 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4353 | if (mService != null) { |
| 4354 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4355 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4356 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4357 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4358 | } |
| 4359 | } |
| 4360 | } |
| 4361 | |
| 4362 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4363 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 4364 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 4365 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4366 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4367 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4368 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 4369 | * none is set. |
| 4370 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4371 | * |
| 4372 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 4373 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4374 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4375 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4376 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 4377 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4378 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4379 | if (mService != null) { |
| 4380 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4381 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4382 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4383 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | return null; |
| 4387 | } |
| 4388 | |
| 4389 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4390 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 4391 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 4392 | * constants. |
| 4393 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 4394 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 4395 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 4396 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 4397 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 4398 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4399 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 4400 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 4401 | * {@code delegatePackage}. |
| 4402 | * |
| 4403 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4404 | * @param delegatePackage The package name of the app which will be given access. |
| 4405 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 4406 | * {@code delegatedPackage}. |
| 4407 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 4408 | */ |
| 4409 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 4410 | @NonNull List<String> scopes) { |
| 4411 | throwIfParentInstance("setDelegatedScopes"); |
| 4412 | if (mService != null) { |
| 4413 | try { |
| 4414 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 4415 | } catch (RemoteException e) { |
| 4416 | throw e.rethrowFromSystemServer(); |
| 4417 | } |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | /** |
| 4422 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 4423 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 4424 | * passing {@code null} for {@code admin} and their own package name as |
| 4425 | * {@code delegatedPackage}. |
| 4426 | * |
| 4427 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4428 | * {@code null} if the caller is {@code delegatedPackage}. |
| 4429 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 4430 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 4431 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 4432 | */ |
| 4433 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 4434 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4435 | @NonNull String delegatedPackage) { |
| 4436 | throwIfParentInstance("getDelegatedScopes"); |
| 4437 | if (mService != null) { |
| 4438 | try { |
| 4439 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 4440 | } catch (RemoteException e) { |
| 4441 | throw e.rethrowFromSystemServer(); |
| 4442 | } |
| 4443 | } |
| 4444 | return null; |
| 4445 | } |
| 4446 | |
| 4447 | /** |
| 4448 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 4449 | * granted a delegation scope. |
| 4450 | * |
| 4451 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4452 | * @param delegationScope The scope whose delegates should be retrieved. |
| 4453 | * @return A list of package names of the current delegated packages for |
| 4454 | {@code delegationScope}. |
| 4455 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 4456 | */ |
| 4457 | @Nullable |
| 4458 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 4459 | @NonNull String delegationScope) { |
| 4460 | throwIfParentInstance("getDelegatePackages"); |
| 4461 | if (mService != null) { |
| 4462 | try { |
| 4463 | return mService.getDelegatePackages(admin, delegationScope); |
| 4464 | } catch (RemoteException e) { |
| 4465 | throw e.rethrowFromSystemServer(); |
| 4466 | } |
| 4467 | } |
| 4468 | return null; |
| 4469 | } |
| 4470 | |
| 4471 | /** |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4472 | * Service-specific error code used in implementation of {@code setAlwaysOnVpnPackage} methods. |
| 4473 | * @hide |
| 4474 | */ |
| 4475 | public static final int ERROR_VPN_PACKAGE_NOT_FOUND = 1; |
| 4476 | |
| 4477 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4478 | * 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] | 4479 | * specific application for the current user. This connection is automatically granted and |
| 4480 | * persisted after a reboot. |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4481 | * <p> To support the always-on feature, an app must |
Charles He | 3673863 | 2017-05-15 17:07:18 +0100 | [diff] [blame] | 4482 | * <ul> |
| 4483 | * <li>declare a {@link android.net.VpnService} in its manifest, guarded by |
| 4484 | * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li> |
| 4485 | * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li> |
| 4486 | * <li><i>not</i> explicitly opt out of the feature through |
Charles He | c57a01c | 2017-08-15 15:30:22 +0100 | [diff] [blame] | 4487 | * {@link android.net.VpnService#SERVICE_META_DATA_SUPPORTS_ALWAYS_ON}.</li> |
Charles He | 3673863 | 2017-05-15 17:07:18 +0100 | [diff] [blame] | 4488 | * </ul> |
| 4489 | * The call will fail if called with the package name of an unsupported VPN app. |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4490 | * <p> Enabling lockdown via {@code lockdownEnabled} argument carries the risk that any failure |
| 4491 | * of the VPN provider could break networking for all apps. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4492 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4493 | * @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] | 4494 | * remove an existing always-on VPN configuration. |
| 4495 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4496 | * {@code false} otherwise. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4497 | * @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] | 4498 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 4499 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 4500 | * set as always-on, or if always-on VPN is not available. |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4501 | * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean, List) |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4502 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 4503 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4504 | boolean lockdownEnabled) throws NameNotFoundException { |
| 4505 | setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled, Collections.emptyList()); |
| 4506 | } |
| 4507 | |
| 4508 | /** |
| 4509 | * A version of {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} that allows the |
| 4510 | * admin to specify a set of apps that should be able to access the network directly when VPN |
| 4511 | * is not connected. When VPN connects these apps switch over to VPN if allowed to use that VPN. |
| 4512 | * System apps can always bypass VPN. |
| 4513 | * <p> Note that the system doesn't update the whitelist when packages are installed or |
| 4514 | * uninstalled, the admin app must call this method to keep the list up to date. |
| 4515 | * |
| 4516 | * @param vpnPackage package name for an installed VPN app on the device, or {@code null} |
| 4517 | * to remove an existing always-on VPN configuration |
| 4518 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 4519 | * {@code false} otherwise. This has no effect when clearing. |
| 4520 | * @param lockdownWhitelist Packages that will be able to access the network directly when VPN |
| 4521 | * is in lockdown mode but not connected. Has no effect when clearing. |
| 4522 | * @throws SecurityException if {@code admin} is not a device or a profile |
| 4523 | * owner. |
| 4524 | * @throws NameNotFoundException if {@code vpnPackage} or one of |
| 4525 | * {@code lockdownWhitelist} is not installed. |
| 4526 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does |
| 4527 | * not support being set as always-on, or if always-on VPN is not |
| 4528 | * available. |
| 4529 | */ |
| 4530 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 4531 | boolean lockdownEnabled, @Nullable List<String> lockdownWhitelist) |
| 4532 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4533 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4534 | if (mService != null) { |
| 4535 | try { |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4536 | mService.setAlwaysOnVpnPackage( |
| 4537 | admin, vpnPackage, lockdownEnabled, lockdownWhitelist); |
| 4538 | } catch (ServiceSpecificException e) { |
| 4539 | switch (e.errorCode) { |
| 4540 | case ERROR_VPN_PACKAGE_NOT_FOUND: |
| 4541 | throw new NameNotFoundException(e.getMessage()); |
| 4542 | default: |
| 4543 | throw new RuntimeException( |
| 4544 | "Unknown error setting always-on VPN: " + e.errorCode, e); |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 4545 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4547 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4548 | } |
| 4549 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | /** |
Pavel Grafov | 5cba336 | 2019-01-25 08:50:06 +0000 | [diff] [blame] | 4553 | * Called by device or profile owner to query whether current always-on VPN is configured in |
| 4554 | * lockdown mode. Returns {@code false} when no always-on configuration is set. |
| 4555 | * |
| 4556 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4557 | * |
| 4558 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 4559 | * |
| 4560 | * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean) |
| 4561 | */ |
| 4562 | public boolean isAlwaysOnVpnLockdownEnabled(@NonNull ComponentName admin) { |
| 4563 | throwIfParentInstance("isAlwaysOnVpnLockdownEnabled"); |
| 4564 | if (mService != null) { |
| 4565 | try { |
| 4566 | return mService.isAlwaysOnVpnLockdownEnabled(admin); |
| 4567 | } catch (RemoteException e) { |
| 4568 | throw e.rethrowFromSystemServer(); |
| 4569 | } |
| 4570 | } |
| 4571 | return false; |
| 4572 | } |
| 4573 | |
| 4574 | /** |
| 4575 | * Called by device or profile owner to query the list of packages that are allowed to access |
| 4576 | * the network directly when always-on VPN is in lockdown mode but not connected. Returns |
| 4577 | * {@code null} when always-on VPN is not active or not in lockdown mode. |
| 4578 | * |
| 4579 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4580 | * |
| 4581 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 4582 | * |
| 4583 | * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean, List) |
| 4584 | */ |
| 4585 | public @Nullable List<String> getAlwaysOnVpnLockdownWhitelist(@NonNull ComponentName admin) { |
| 4586 | throwIfParentInstance("getAlwaysOnVpnLockdownWhitelist"); |
| 4587 | if (mService != null) { |
| 4588 | try { |
| 4589 | return mService.getAlwaysOnVpnLockdownWhitelist(admin); |
| 4590 | } catch (RemoteException e) { |
| 4591 | throw e.rethrowFromSystemServer(); |
| 4592 | } |
| 4593 | } |
| 4594 | return null; |
| 4595 | } |
| 4596 | |
| 4597 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4598 | * 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] | 4599 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 4600 | * 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] | 4601 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4602 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 4603 | * is set. |
| 4604 | * @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] | 4605 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4606 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4607 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4608 | if (mService != null) { |
| 4609 | try { |
| 4610 | return mService.getAlwaysOnVpnPackage(admin); |
| 4611 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4612 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4613 | } |
| 4614 | } |
| 4615 | return null; |
| 4616 | } |
| 4617 | |
| 4618 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4619 | * Called by an application that is administering the device to disable all cameras on the |
| 4620 | * device, for this user. After setting this, no applications running as this user will be able |
| 4621 | * to access any cameras on the device. |
| 4622 | * <p> |
| 4623 | * If the caller is device owner, then the restriction will be applied to all users. |
| 4624 | * <p> |
| 4625 | * The calling device admin must have requested |
| 4626 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 4627 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4628 | * |
| 4629 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4630 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4631 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4632 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4633 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4634 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4635 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4636 | if (mService != null) { |
| 4637 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4638 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4639 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4640 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4646 | * 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] | 4647 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4648 | * @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] | 4649 | * have disabled the camera |
| 4650 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4651 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4652 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4653 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | /** @hide per-user version */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4657 | @UnsupportedAppUsage |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4658 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4659 | if (mService != null) { |
| 4660 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4661 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4662 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4663 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4664 | } |
| 4665 | } |
| 4666 | return false; |
| 4667 | } |
| 4668 | |
| 4669 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4670 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4671 | * <p> |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 4672 | * If the device contains secondary users or profiles, they must be affiliated with the device. |
| 4673 | * Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4674 | * |
| 4675 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4676 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 4677 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 4678 | * 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] | 4679 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 4680 | * profile or secondary user that is not affiliated with the device. |
| 4681 | * @see #isAffiliatedUser |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4682 | */ |
| 4683 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4684 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4685 | if (mService != null) { |
| 4686 | try { |
| 4687 | return mService.requestBugreport(admin); |
| 4688 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4689 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | return false; |
| 4693 | } |
| 4694 | |
| 4695 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 4696 | * Determine whether or not creating a guest user has been disabled for the device |
| 4697 | * |
| 4698 | * @hide |
| 4699 | */ |
| 4700 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 4701 | // Currently guest users can always be created if multi-user is enabled |
| 4702 | // TODO introduce a policy for guest user creation |
| 4703 | return false; |
| 4704 | } |
| 4705 | |
| 4706 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 4707 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 4708 | * screen capture also prevents the content from being shown on display devices that do not have |
| 4709 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 4710 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4711 | * <p> |
| 4712 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4713 | * exception will be thrown. |
| 4714 | * <p> |
| 4715 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 4716 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 4717 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4718 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4719 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4720 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4721 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4722 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4723 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4724 | if (mService != null) { |
| 4725 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4726 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4727 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4728 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4729 | } |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4734 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4735 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4736 | * @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] | 4737 | * have disabled screen capture. |
| 4738 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4739 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4740 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4741 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4745 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4746 | if (mService != null) { |
| 4747 | try { |
| 4748 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 4749 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4750 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4751 | } |
| 4752 | } |
| 4753 | return false; |
| 4754 | } |
| 4755 | |
| 4756 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4757 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 4758 | * required, no user will be able set the date and time and network date and time will be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4759 | * <p> |
| 4760 | * Note: if auto time is required the user can still manually set the time zone. |
| 4761 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4762 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4763 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4764 | * |
| 4765 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4766 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4767 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4768 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4769 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4770 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4771 | if (mService != null) { |
| 4772 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4773 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4774 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4775 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4776 | } |
| 4777 | } |
| 4778 | } |
| 4779 | |
| 4780 | /** |
| 4781 | * @return true if auto time is required. |
| 4782 | */ |
| 4783 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4784 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4785 | if (mService != null) { |
| 4786 | try { |
| 4787 | return mService.getAutoTimeRequired(); |
| 4788 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4789 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4790 | } |
| 4791 | } |
| 4792 | return false; |
| 4793 | } |
| 4794 | |
| 4795 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4796 | * 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] | 4797 | * <p> |
| 4798 | * The system user is exempt from this policy - it is never ephemeral. |
| 4799 | * <p> |
| 4800 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4801 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4802 | * |
| 4803 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4804 | * @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] | 4805 | * subsequently created users will be ephemeral. |
| 4806 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4807 | * @hide |
| 4808 | */ |
| 4809 | public void setForceEphemeralUsers( |
| 4810 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4811 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4812 | if (mService != null) { |
| 4813 | try { |
| 4814 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 4815 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4816 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4817 | } |
| 4818 | } |
| 4819 | } |
| 4820 | |
| 4821 | /** |
| 4822 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4823 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4824 | * @hide |
| 4825 | */ |
| 4826 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4827 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4828 | if (mService != null) { |
| 4829 | try { |
| 4830 | return mService.getForceEphemeralUsers(admin); |
| 4831 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4832 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4833 | } |
| 4834 | } |
| 4835 | return false; |
| 4836 | } |
| 4837 | |
| 4838 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4839 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4840 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4841 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4842 | * <p> |
| 4843 | * The calling device admin must have requested |
| 4844 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4845 | * if it has not, a security exception will be thrown. |
| 4846 | * <p> |
| 4847 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4848 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4849 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4850 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4851 | * <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] | 4852 | * is no separate challenge set on the managed profile. |
Rubin Xu | c418d5a | 2018-05-02 12:18:18 +0100 | [diff] [blame] | 4853 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FACE} or |
| 4854 | * {@link #KEYGUARD_DISABLE_IRIS} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4855 | * there is one, or the parent user otherwise. |
| 4856 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4857 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4858 | * </ul> |
Rubin Xu | c418d5a | 2018-05-02 12:18:18 +0100 | [diff] [blame] | 4859 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 4860 | * {@link #KEYGUARD_DISABLE_FACE} and {@link #KEYGUARD_DISABLE_IRIS} can also be |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4861 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4862 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4863 | * profile. |
| 4864 | * <p> |
| 4865 | * Requests to disable other features on a managed profile will be ignored. |
| 4866 | * <p> |
| 4867 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4868 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4869 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4870 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | c418d5a | 2018-05-02 12:18:18 +0100 | [diff] [blame] | 4871 | * @param which The disabled features flag which can be either |
| 4872 | * {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 4873 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL}, or a combination of |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4874 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4875 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4876 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4877 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
Rubin Xu | c418d5a | 2018-05-02 12:18:18 +0100 | [diff] [blame] | 4878 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 4879 | * {@link #KEYGUARD_DISABLE_FACE}, |
| 4880 | * {@link #KEYGUARD_DISABLE_IRIS}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4881 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4882 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4883 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4884 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4885 | if (mService != null) { |
| 4886 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4887 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4888 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4889 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4890 | } |
| 4891 | } |
| 4892 | } |
| 4893 | |
| 4894 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4895 | * 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] | 4896 | * 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] | 4897 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4898 | * |
| 4899 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4900 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4901 | * restrictions on the parent profile. |
| 4902 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4903 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4904 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4905 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4906 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4907 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4908 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4909 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | /** @hide per-user version */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4913 | @UnsupportedAppUsage |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4914 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4915 | if (mService != null) { |
| 4916 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4917 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4918 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4919 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4920 | } |
| 4921 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4922 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4926 | * @hide |
| 4927 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4928 | @UnsupportedAppUsage |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4929 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4930 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4931 | if (mService != null) { |
| 4932 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4933 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4934 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4935 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4936 | } |
| 4937 | } |
| 4938 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4939 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4940 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4941 | * @hide |
| 4942 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4943 | @UnsupportedAppUsage |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4944 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4945 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4949 | * @hide |
| 4950 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4951 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4952 | if (mService != null) { |
| 4953 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4954 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4955 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4956 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4957 | } |
| 4958 | } |
| 4959 | } |
| 4960 | |
| 4961 | /** |
| 4962 | * @hide |
| 4963 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4964 | @UnsupportedAppUsage |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4965 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4966 | if (mService != null) { |
| 4967 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4968 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4969 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4970 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4971 | } |
| 4972 | } |
| 4973 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4974 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4975 | /** |
| 4976 | * @hide |
| 4977 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4978 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4979 | if (mService != null) { |
| 4980 | try { |
| 4981 | mService.reportPasswordChanged(userId); |
| 4982 | } catch (RemoteException e) { |
| 4983 | throw e.rethrowFromSystemServer(); |
| 4984 | } |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | /** |
| 4989 | * @hide |
| 4990 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4991 | @UnsupportedAppUsage |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4992 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4993 | if (mService != null) { |
| 4994 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4995 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4996 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4997 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4998 | } |
| 4999 | } |
| 5000 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 5001 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5002 | /** |
| 5003 | * @hide |
| 5004 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5005 | @UnsupportedAppUsage |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 5006 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5007 | if (mService != null) { |
| 5008 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 5009 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5010 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5011 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5015 | |
| 5016 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 5017 | * @hide |
| 5018 | */ |
| 5019 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 5020 | if (mService != null) { |
| 5021 | try { |
| 5022 | mService.reportFailedFingerprintAttempt(userHandle); |
| 5023 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5024 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 5025 | } |
| 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | /** |
| 5030 | * @hide |
| 5031 | */ |
| 5032 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 5033 | if (mService != null) { |
| 5034 | try { |
| 5035 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 5036 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5037 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 5038 | } |
| 5039 | } |
| 5040 | } |
| 5041 | |
| 5042 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 5043 | * Should be called when keyguard has been dismissed. |
| 5044 | * @hide |
| 5045 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 5046 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 5047 | if (mService != null) { |
| 5048 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 5049 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 5050 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5051 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 5052 | } |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | /** |
| 5057 | * Should be called when keyguard view has been shown to the user. |
| 5058 | * @hide |
| 5059 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 5060 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 5061 | if (mService != null) { |
| 5062 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 5063 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 5064 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5065 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 5066 | } |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5071 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 5072 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5073 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 5074 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5075 | * @return whether the package was successfully registered as the device owner. |
| 5076 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 5077 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5078 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5079 | public boolean setDeviceOwner(ComponentName who) { |
| 5080 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 5081 | } |
| 5082 | |
| 5083 | /** |
| 5084 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 5085 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5086 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 5087 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | /** |
| 5091 | * @hide |
| 5092 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5093 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 5094 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | /** |
| 5098 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 5099 | * Sets the given package as the device owner. The package must already be installed. There |
| 5100 | * must not already be a device owner. |
| 5101 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 5102 | * this method. |
| 5103 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 5104 | * 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] | 5105 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 5106 | * @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] | 5107 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 5108 | * @return whether the package was successfully registered as the device owner. |
| 5109 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 5110 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 5111 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5112 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 5113 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5114 | if (mService != null) { |
| 5115 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5116 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5117 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5118 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5119 | } |
| 5120 | } |
| 5121 | return false; |
| 5122 | } |
| 5123 | |
| 5124 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 5125 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 5126 | * 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] | 5127 | * 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] | 5128 | * package is currently registered as the device owner app, pass in the package name from |
| 5129 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5130 | * 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] | 5131 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 5132 | * the setup process. |
| 5133 | * @param packageName the package name of the app, to compare with the registered device owner |
| 5134 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5135 | * @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] | 5136 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 5137 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5138 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5139 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 5140 | } |
| 5141 | |
| 5142 | /** |
| 5143 | * @return true if a package is registered as device owner, only when it's running on the |
| 5144 | * calling user. |
| 5145 | * |
| 5146 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 5147 | * @hide |
| 5148 | */ |
| 5149 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 5150 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 5151 | } |
| 5152 | |
| 5153 | /** |
| 5154 | * @return true if a package is registered as device owner, even if it's running on a different |
| 5155 | * user. |
| 5156 | * |
| 5157 | * <p>Requires the MANAGE_USERS permission. |
| 5158 | * |
| 5159 | * @hide |
| 5160 | */ |
| 5161 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 5162 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 5163 | } |
| 5164 | |
| 5165 | /** |
| 5166 | * @return device owner component name, only when it's running on the calling user. |
| 5167 | * |
| 5168 | * @hide |
| 5169 | */ |
| 5170 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 5171 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 5172 | } |
| 5173 | |
| 5174 | /** |
| 5175 | * @return device owner component name, even if it's running on a different user. |
| 5176 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5177 | * @hide |
| 5178 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 5179 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5180 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5181 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 5182 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 5183 | } |
| 5184 | |
| 5185 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 5186 | if (packageName == null) { |
| 5187 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5188 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5189 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 5190 | if (deviceOwner == null) { |
| 5191 | return false; |
| 5192 | } |
| 5193 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5196 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 5197 | if (mService != null) { |
| 5198 | try { |
| 5199 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 5200 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5201 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5202 | } |
| 5203 | } |
| 5204 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 5205 | } |
| 5206 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 5207 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5208 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 5209 | * no device owner. |
| 5210 | * |
| 5211 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5212 | * |
| 5213 | * @hide |
| 5214 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5215 | public int getDeviceOwnerUserId() { |
| 5216 | if (mService != null) { |
| 5217 | try { |
| 5218 | return mService.getDeviceOwnerUserId(); |
| 5219 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5220 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5221 | } |
| 5222 | } |
| 5223 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5227 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 5228 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 5229 | * a part of device setup, before it completes. |
| 5230 | * <p> |
| 5231 | * While some policies previously set by the device owner will be cleared by this method, it is |
| 5232 | * a best-effort process and some other policies will still remain in place after the device |
| 5233 | * owner is cleared. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 5234 | * |
| 5235 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5236 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 5237 | * does not own the current device owner component. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 5238 | * |
| 5239 | * @deprecated This method is expected to be used for testing purposes only. The device owner |
| 5240 | * will lose control of the device and its data after calling it. In order to protect any |
| 5241 | * sensitive data that remains on the device, it is advised that the device owner factory resets |
| 5242 | * the device instead of calling this method. See {@link #wipeData(int)}. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 5243 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 5244 | @Deprecated |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 5245 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5246 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 5247 | if (mService != null) { |
| 5248 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 5249 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 5250 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5251 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 5252 | } |
| 5253 | } |
| 5254 | } |
| 5255 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5256 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5257 | * Returns the device owner package name, only if it's running on the calling user. |
| 5258 | * |
| 5259 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5260 | * |
| 5261 | * @hide |
| 5262 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 5263 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5264 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5265 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5266 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5267 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 5268 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 5272 | * 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] | 5273 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 5274 | * @return whether the device is managed by a Device Owner. |
| 5275 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 5276 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5277 | * |
| 5278 | * @hide |
| 5279 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 5280 | @SystemApi |
| 5281 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5282 | @SuppressLint("Doclava125") |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5283 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 5284 | try { |
| 5285 | return mService.hasDeviceOwner(); |
| 5286 | } catch (RemoteException re) { |
| 5287 | throw re.rethrowFromSystemServer(); |
| 5288 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | /** |
| 5292 | * Returns the device owner name. Note this method *will* return the device owner |
| 5293 | * name when it's running on a different user. |
| 5294 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5295 | * @hide |
| 5296 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 5297 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5298 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5299 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5300 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5301 | if (mService != null) { |
| 5302 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 5303 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 5304 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5305 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | return null; |
| 5309 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5310 | |
| 5311 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 5312 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 5313 | * @deprecated Do not use |
| 5314 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5315 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 5316 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5317 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 5318 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5319 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5320 | return null; |
| 5321 | } |
| 5322 | |
| 5323 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 5324 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 5325 | * @deprecated Do not use |
| 5326 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 5327 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 5328 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 5329 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 5330 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5331 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 5332 | return null; |
| 5333 | } |
| 5334 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5335 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5336 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5337 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 5338 | * Sets the given component as an active admin and registers the package as the profile |
| 5339 | * owner for this user. The package must already be installed and there shouldn't be |
| 5340 | * an existing profile owner registered for this user. Also, this method must be called |
| 5341 | * before the user setup has been completed. |
| 5342 | * <p> |
| 5343 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 5344 | * MANAGE_DEVICE_ADMINS permission. |
| 5345 | * @param admin The component to register as an active admin and profile owner. |
| 5346 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 5347 | * @return whether the admin was successfully registered as the profile owner. |
| 5348 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 5349 | * the user has already been set up. |
| 5350 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 5351 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 5352 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 5353 | @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5354 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 5355 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5356 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 5357 | if (mService != null) { |
| 5358 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5359 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 5360 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5361 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 5362 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5363 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | return false; |
| 5367 | } |
| 5368 | |
| 5369 | /** |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 5370 | * Clears the active profile owner. The caller must be the profile owner of this user, otherwise |
| 5371 | * a SecurityException will be thrown. This method is not available to managed profile owners. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5372 | * <p> |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 5373 | * While some policies previously set by the profile owner will be cleared by this method, it is |
| 5374 | * a best-effort process and some other policies will still remain in place after the profile |
| 5375 | * owner is cleared. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 5376 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5377 | * @param admin The component to remove as the profile owner. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 5378 | * @throws SecurityException if {@code admin} is not an active profile owner, or the method is |
| 5379 | * being called from a managed profile. |
| 5380 | * |
| 5381 | * @deprecated This method is expected to be used for testing purposes only. The profile owner |
| 5382 | * will lose control of the user and its data after calling it. In order to protect any |
| 5383 | * sensitive data that remains on this user, it is advised that the profile owner deletes it |
| 5384 | * instead of calling this method. See {@link #wipeData(int)}. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5385 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 5386 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5387 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5388 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5389 | if (mService != null) { |
| 5390 | try { |
| 5391 | mService.clearProfileOwner(admin); |
| 5392 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5393 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5394 | } |
| 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5399 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5400 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5401 | */ |
| 5402 | public boolean hasUserSetupCompleted() { |
| 5403 | if (mService != null) { |
| 5404 | try { |
| 5405 | return mService.hasUserSetupCompleted(); |
| 5406 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5407 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5408 | } |
| 5409 | } |
| 5410 | return true; |
| 5411 | } |
| 5412 | |
| 5413 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5414 | * @hide |
| 5415 | * 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] | 5416 | * already be installed. There must not already be a profile owner for this user. |
| 5417 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 5418 | * this method. |
| 5419 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 5420 | * - the caller is SYSTEM_UID. |
| 5421 | * - 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] | 5422 | * @param admin the component name to be registered as profile owner. |
| 5423 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5424 | * @param userHandle the userId to set the profile owner for. |
| 5425 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 5426 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 5427 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5429 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 5430 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5431 | if (mService != null) { |
| 5432 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 5433 | if (ownerName == null) { |
| 5434 | ownerName = ""; |
| 5435 | } |
| 5436 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5437 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5438 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5439 | } |
| 5440 | } |
| 5441 | return false; |
| 5442 | } |
| 5443 | |
| 5444 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5445 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5446 | * <p> |
| 5447 | * 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] | 5448 | * 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] | 5449 | * <p> |
| 5450 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 5451 | * will be blank and the user will not be allowed to change it. |
| 5452 | * <p> |
| 5453 | * 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] | 5454 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5455 | * and set a new version of this string accordingly. |
| 5456 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5457 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5458 | * @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] | 5459 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5460 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 5461 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5462 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5463 | if (mService != null) { |
| 5464 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 5465 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5466 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5467 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5468 | } |
| 5469 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | /** |
| 5473 | * @return The device owner information. If it is not set returns {@code null}. |
| 5474 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 5475 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5476 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5477 | if (mService != null) { |
| 5478 | try { |
| 5479 | return mService.getDeviceOwnerLockScreenInfo(); |
| 5480 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5481 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 5482 | } |
| 5483 | } |
| 5484 | return null; |
| 5485 | } |
| 5486 | |
| 5487 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5488 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 5489 | * called by a device owner, profile owner, or by a delegate given the |
| 5490 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5491 | * <p> |
| 5492 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 5493 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 5494 | * device. |
| 5495 | * <p> |
| 5496 | * The package must already be installed. If the package is uninstalled while suspended the |
| 5497 | * 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] | 5498 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5499 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5500 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 5501 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 5502 | * @param packageNames The package names to suspend or unsuspend. |
| 5503 | * @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] | 5504 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 5505 | * @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] | 5506 | * this method. |
| 5507 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5508 | * @see #setDelegatedScopes |
| 5509 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5510 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5511 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 5512 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5513 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5514 | if (mService != null) { |
| 5515 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5516 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 5517 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5518 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5519 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5520 | } |
| 5521 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 5522 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5526 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 5527 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 5528 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5529 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5530 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5531 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5532 | * @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] | 5533 | * @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] | 5534 | * suspended, could not be found or an error occurred. |
| 5535 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 5536 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5537 | * @see #setDelegatedScopes |
| 5538 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5539 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 5540 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 5541 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5542 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5543 | if (mService != null) { |
| 5544 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5545 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5547 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 5548 | } catch (IllegalArgumentException ex) { |
| 5549 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5550 | } |
| 5551 | } |
| 5552 | return false; |
| 5553 | } |
| 5554 | |
| 5555 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5556 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 5557 | * be used. Only the profile owner can call this. |
| 5558 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 5559 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5560 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5561 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5562 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5563 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5564 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5565 | if (mService != null) { |
| 5566 | try { |
| 5567 | mService.setProfileEnabled(admin); |
| 5568 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5569 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5570 | } |
| 5571 | } |
| 5572 | } |
| 5573 | |
| 5574 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5575 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 5576 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 5577 | * 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] | 5578 | * |
| 5579 | * @see #isProfileOwnerApp |
| 5580 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5581 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5582 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5583 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5584 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5585 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5586 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5587 | if (mService != null) { |
| 5588 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5589 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 5590 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5591 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 5592 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5593 | } |
| 5594 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5595 | |
| 5596 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5597 | * 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] | 5598 | * 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] | 5599 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5600 | * |
| 5601 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 5602 | * @return Whether or not the package is registered as the profile owner. |
| 5603 | */ |
| 5604 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5605 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5606 | if (mService != null) { |
| 5607 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 5608 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 5609 | return profileOwner != null |
| 5610 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5611 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5612 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5613 | } |
| 5614 | } |
| 5615 | return false; |
| 5616 | } |
| 5617 | |
| 5618 | /** |
| 5619 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5620 | * @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] | 5621 | * owner has been set for that user. |
| 5622 | * @throws IllegalArgumentException if the userId is invalid. |
| 5623 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 5624 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5625 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5626 | throwIfParentInstance("getProfileOwner"); |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 5627 | return getProfileOwnerAsUser(mContext.getUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | /** |
| 5631 | * @see #getProfileOwner() |
| 5632 | * @hide |
| 5633 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5634 | @UnsupportedAppUsage |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5635 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 5636 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5637 | if (mService != null) { |
| 5638 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 5639 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5640 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5641 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5642 | } |
| 5643 | } |
| 5644 | return null; |
| 5645 | } |
| 5646 | |
| 5647 | /** |
| 5648 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5649 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 5650 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5651 | * @throws IllegalArgumentException if the userId is invalid. |
| 5652 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5653 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5654 | if (mService != null) { |
| 5655 | try { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 5656 | return mService.getProfileOwnerName(mContext.getUserId()); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5657 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5658 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5659 | } |
| 5660 | } |
| 5661 | return null; |
| 5662 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5663 | |
| 5664 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5665 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5666 | * @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] | 5667 | * @return the human readable name of the organisation associated with this profile owner or |
| 5668 | * null if one is not set. |
| 5669 | * @throws IllegalArgumentException if the userId is invalid. |
| 5670 | */ |
| 5671 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5672 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5673 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5674 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5675 | if (mService != null) { |
| 5676 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 5677 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5678 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5679 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5680 | } |
| 5681 | } |
| 5682 | return null; |
| 5683 | } |
| 5684 | |
| 5685 | /** |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 5686 | * Called by a profile owner or device owner to set a default activity that the system selects |
| 5687 | * to handle intents that match the given {@link IntentFilter}. This activity will remain the |
| 5688 | * default intent handler even if the set of potential event handlers for the intent filter |
| 5689 | * changes and if the intent preferences are reset. |
| 5690 | * <p> |
| 5691 | * Note that the caller should still declare the activity in the manifest, the API just sets |
| 5692 | * the activity to be the default one to handle the given intent filter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5693 | * <p> |
| 5694 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 5695 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 5696 | * the filter. |
| 5697 | * <p> |
| 5698 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 5699 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5700 | * |
| 5701 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5702 | * @param filter The IntentFilter for which a default handler is added. |
| 5703 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5704 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5705 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5706 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 5707 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5708 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5709 | if (mService != null) { |
| 5710 | try { |
| 5711 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 5712 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5713 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5714 | } |
| 5715 | } |
| 5716 | } |
| 5717 | |
| 5718 | /** |
| 5719 | * 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] | 5720 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5721 | * <p> |
| 5722 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5723 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5724 | * |
| 5725 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5726 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5727 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5728 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5729 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5730 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5731 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5732 | if (mService != null) { |
| 5733 | try { |
| 5734 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 5735 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5736 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5737 | } |
| 5738 | } |
| 5739 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5740 | |
| 5741 | /** |
Christine Franks | 26449ed | 2018-02-22 16:19:26 -0800 | [diff] [blame] | 5742 | * Called by a device owner to set the default SMS application. |
| 5743 | * <p> |
| 5744 | * The calling device admin must be a device owner. If it is not, a security exception will be |
| 5745 | * thrown. |
| 5746 | * |
| 5747 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5748 | * @param packageName The name of the package to set as the default SMS application. |
| 5749 | * @throws SecurityException if {@code admin} is not a device owner. |
| 5750 | * |
| 5751 | * @hide |
| 5752 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5753 | @UnsupportedAppUsage |
Christine Franks | 26449ed | 2018-02-22 16:19:26 -0800 | [diff] [blame] | 5754 | public void setDefaultSmsApplication(@NonNull ComponentName admin, String packageName) { |
| 5755 | throwIfParentInstance("setDefaultSmsApplication"); |
| 5756 | if (mService != null) { |
| 5757 | try { |
| 5758 | mService.setDefaultSmsApplication(admin, packageName); |
| 5759 | } catch (RemoteException e) { |
| 5760 | throw e.rethrowFromSystemServer(); |
| 5761 | } |
| 5762 | } |
| 5763 | } |
| 5764 | |
| 5765 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5766 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 5767 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 5768 | * {@link #getApplicationRestrictions}. |
| 5769 | * <p> |
| 5770 | * This permission is persistent until it is later cleared by calling this method with a |
| 5771 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 5772 | * <p> |
| 5773 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5774 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5775 | * |
| 5776 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5777 | * @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] | 5778 | * APIs. If {@code null} is given the current package will be cleared. |
| 5779 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5780 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5781 | * |
| 5782 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 5783 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5784 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5785 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5786 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5787 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5788 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5789 | if (mService != null) { |
| 5790 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5791 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 5792 | throw new NameNotFoundException(packageName); |
| 5793 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5794 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5795 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5796 | } |
| 5797 | } |
| 5798 | } |
| 5799 | |
| 5800 | /** |
| 5801 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5802 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 5803 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5804 | * |
| 5805 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5806 | * @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] | 5807 | * {@code null} if none is set. |
| 5808 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5809 | * |
| 5810 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 5811 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5812 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5813 | @Deprecated |
| 5814 | @Nullable |
| 5815 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5816 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5817 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5818 | if (mService != null) { |
| 5819 | try { |
| 5820 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 5821 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5822 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5823 | } |
| 5824 | } |
| 5825 | return null; |
| 5826 | } |
| 5827 | |
| 5828 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 5829 | * Called by any application to find out whether it has been granted permission via |
| 5830 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 5831 | * for the calling user. |
| 5832 | * |
| 5833 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 5834 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5835 | * |
| 5836 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 5837 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5838 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5839 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5840 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5841 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5842 | if (mService != null) { |
| 5843 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5844 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 5845 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5846 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5847 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5848 | } |
| 5849 | } |
| 5850 | return false; |
| 5851 | } |
| 5852 | |
| 5853 | /** |
| 5854 | * 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] | 5855 | * <p> |
| 5856 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5857 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5858 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5859 | * <p> |
| 5860 | * 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] | 5861 | * <ul> |
| 5862 | * <li>{@code boolean} |
| 5863 | * <li>{@code int} |
| 5864 | * <li>{@code String} or {@code String[]} |
| 5865 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5866 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5867 | * <p> |
| 5868 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5869 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5870 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5871 | * <p> |
| 5872 | * The application restrictions are only made visible to the target application via |
| 5873 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5874 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5875 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5876 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5877 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5878 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5879 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5880 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5881 | * @param packageName The name of the package to update restricted settings for. |
| 5882 | * @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] | 5883 | * set of active restrictions. |
| 5884 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5885 | * @see #setDelegatedScopes |
| 5886 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5887 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5888 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5889 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5890 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5891 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5892 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5893 | if (mService != null) { |
| 5894 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5895 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5896 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5897 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5898 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
| 5903 | /** |
Rubin Xu | 50ac241 | 2018-03-02 15:25:28 +0000 | [diff] [blame] | 5904 | * Sets a list of configuration features to enable for a trust agent component. This is meant to |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5905 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5906 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5907 | * {@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] | 5908 | * <p> |
Rubin Xu | 50ac241 | 2018-03-02 15:25:28 +0000 | [diff] [blame] | 5909 | * For any specific trust agent, whether it is disabled or not depends on the aggregated state |
| 5910 | * of each admin's {@link #KEYGUARD_DISABLE_TRUST_AGENTS} setting and its trust agent |
| 5911 | * configuration as set by this function call. In particular: if any admin sets |
| 5912 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and does not additionally set any |
| 5913 | * trust agent configuration, the trust agent is disabled completely. Otherwise, the trust agent |
| 5914 | * will receive the list of configurations from all admins who set |
| 5915 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and aggregate the configurations to determine its |
| 5916 | * behavior. The exact meaning of aggregation is trust-agent-specific. |
| 5917 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5918 | * The calling device admin must have requested |
| 5919 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5920 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5921 | * <p> |
| 5922 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5923 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5924 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5925 | * |
| 5926 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | 50ac241 | 2018-03-02 15:25:28 +0000 | [diff] [blame] | 5927 | * @param target Component name of the agent to be configured. |
| 5928 | * @param configuration Trust-agent-specific feature configuration bundle. Please consult |
| 5929 | * documentation of the specific trust agent to determine the interpretation of this |
| 5930 | * bundle. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5931 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5932 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5933 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5934 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5935 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5936 | if (mService != null) { |
| 5937 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5938 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5939 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5940 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5941 | } |
| 5942 | } |
| 5943 | } |
| 5944 | |
| 5945 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5946 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5947 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5948 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5949 | * <p> |
| 5950 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5951 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5952 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5953 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5954 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5955 | * this function returns a list of configurations for all admins that declare |
| 5956 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5957 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5958 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5959 | * 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] | 5960 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5961 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5962 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5963 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5964 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5965 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | /** @hide per-user version */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5969 | @UnsupportedAppUsage |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5970 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5971 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5972 | if (mService != null) { |
| 5973 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5974 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5975 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5976 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5977 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5978 | } |
| 5979 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5980 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5984 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5985 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5986 | * <p> |
| 5987 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5988 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5989 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5990 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5991 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 5992 | * @throws SecurityException if {@code admin} is not a profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5993 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5994 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5995 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5996 | if (mService != null) { |
| 5997 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5998 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5999 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6000 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 6001 | } |
| 6002 | } |
| 6003 | } |
| 6004 | |
| 6005 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6006 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 6007 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6008 | * <p> |
| 6009 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 6010 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 6011 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6012 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6013 | * @throws SecurityException if {@code admin} is not a profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 6014 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6015 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6016 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 6017 | if (mService != null) { |
| 6018 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6019 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 6020 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6021 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 6022 | } |
| 6023 | } |
| 6024 | return false; |
| 6025 | } |
| 6026 | |
| 6027 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 6028 | * Determine whether or not caller-Id information has been disabled. |
| 6029 | * |
| 6030 | * @param userHandle The user for whom to check the caller-id permission |
| 6031 | * @hide |
| 6032 | */ |
| 6033 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 6034 | if (mService != null) { |
| 6035 | try { |
| 6036 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 6037 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6038 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 6039 | } |
| 6040 | } |
| 6041 | return false; |
| 6042 | } |
| 6043 | |
| 6044 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6045 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 6046 | * managed profile will be shown in the parent profile, for incoming calls. |
| 6047 | * <p> |
| 6048 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 6049 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6050 | * |
| 6051 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6052 | * @param disabled If true contacts search in the managed profile is not displayed. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6053 | * @throws SecurityException if {@code admin} is not a profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6054 | */ |
| 6055 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 6056 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6057 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6058 | if (mService != null) { |
| 6059 | try { |
| 6060 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 6061 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6062 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6063 | } |
| 6064 | } |
| 6065 | } |
| 6066 | |
| 6067 | /** |
| 6068 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 6069 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6070 | * <p> |
| 6071 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 6072 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6073 | * |
| 6074 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6075 | * @throws SecurityException if {@code admin} is not a profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6076 | */ |
| 6077 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6078 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6079 | if (mService != null) { |
| 6080 | try { |
| 6081 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 6082 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6083 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6084 | } |
| 6085 | } |
| 6086 | return false; |
| 6087 | } |
| 6088 | |
| 6089 | |
| 6090 | /** |
| 6091 | * Determine whether or not contacts search has been disabled. |
| 6092 | * |
| 6093 | * @param userHandle The user for whom to check the contacts search permission |
| 6094 | * @hide |
| 6095 | */ |
| 6096 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 6097 | if (mService != null) { |
| 6098 | try { |
| 6099 | return mService |
| 6100 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 6101 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6102 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | return false; |
| 6106 | } |
| 6107 | |
| 6108 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6109 | * 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] | 6110 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 6111 | * @hide |
| 6112 | */ |
| 6113 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 6114 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 6115 | if (mService != null) { |
| 6116 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 6117 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 6118 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 6119 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6120 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 6121 | } |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6126 | * 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] | 6127 | * @hide |
| 6128 | */ |
| 6129 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 6130 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 6131 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 6132 | originalIntent); |
| 6133 | } |
| 6134 | |
| 6135 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6136 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 6137 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6138 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6139 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 6140 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6141 | * <p> |
| 6142 | * This API works on managed profile only. |
| 6143 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6144 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6145 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6146 | * @throws SecurityException if {@code admin} is not a profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6147 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6148 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6149 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6150 | if (mService != null) { |
| 6151 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6152 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6153 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6154 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6155 | } |
| 6156 | } |
| 6157 | } |
| 6158 | |
| 6159 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6160 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 6161 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6162 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6163 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 6164 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6165 | * <p> |
| 6166 | * This API works on managed profile only. |
| 6167 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6168 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6169 | * @throws SecurityException if {@code admin} is not a profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6170 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6171 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6172 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6173 | if (mService != null) { |
| 6174 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6175 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6176 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6177 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6178 | } |
| 6179 | } |
| 6180 | return true; |
| 6181 | } |
| 6182 | |
| 6183 | /** |
| 6184 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 6185 | * <p> |
| 6186 | * This API works on managed profile UserHandle only. |
| 6187 | * |
| 6188 | * @param userHandle The user for whom to check the caller-id permission |
| 6189 | * @hide |
| 6190 | */ |
| 6191 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 6192 | if (mService != null) { |
| 6193 | try { |
| 6194 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 6195 | .getIdentifier()); |
| 6196 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6197 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 6198 | } |
| 6199 | } |
| 6200 | return true; |
| 6201 | } |
| 6202 | |
| 6203 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6204 | * 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] | 6205 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 6206 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 6207 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6208 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 6209 | * @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] | 6210 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 6211 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6212 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 6213 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6214 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6215 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6216 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6217 | if (mService != null) { |
| 6218 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 6219 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6220 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6221 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | } |
| 6225 | |
| 6226 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6227 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 6228 | * 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] | 6229 | * Only removes those that have been set by the profile owner. |
Rubin Xu | cc391c2 | 2018-01-02 20:37:35 +0000 | [diff] [blame] | 6230 | * <p> |
| 6231 | * <em>Note</em>: A list of default cross profile intent filters are set up by the system when |
| 6232 | * the profile is created, some of them ensure the proper functioning of the profile, while |
| 6233 | * others enable sharing of data from the parent to the managed profile for user convenience. |
| 6234 | * These default intent filters are not cleared when this API is called. If the default cross |
| 6235 | * profile data sharing is not desired, they can be disabled with |
| 6236 | * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6237 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6238 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6239 | * @throws SecurityException if {@code admin} is not a profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6240 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6241 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6242 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6243 | if (mService != null) { |
| 6244 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 6245 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6246 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6247 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 6248 | } |
| 6249 | } |
| 6250 | } |
| 6251 | |
| 6252 | /** |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6253 | * Called by a profile or device owner to set the permitted |
| 6254 | * {@link android.accessibilityservice.AccessibilityService}. When set by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6255 | * a device owner or profile owner the restriction applies to all profiles of the user the |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6256 | * device owner or profile owner is an admin for. By default, the user can use any accessibility |
| 6257 | * service. When zero or more packages have been added, accessibility services that are not in |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6258 | * the list and not part of the system can not be enabled by the user. |
| 6259 | * <p> |
| 6260 | * Calling with a null value for the list disables the restriction so that all services can be |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6261 | * used, calling with an empty list only allows the built-in system services. Any non-system |
| 6262 | * accessibility service that's currently enabled must be included in the list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6263 | * <p> |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 6264 | * System accessibility 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] | 6265 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6266 | * @param packageNames List of accessibility service package names. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6267 | * @return {@code true} if the operation succeeded, or {@code false} if the list didn't |
| 6268 | * contain every enabled non-system accessibility service. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6269 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6270 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6271 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6272 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6273 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6274 | if (mService != null) { |
| 6275 | try { |
| 6276 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 6277 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6278 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6279 | } |
| 6280 | } |
| 6281 | return false; |
| 6282 | } |
| 6283 | |
| 6284 | /** |
| 6285 | * 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] | 6286 | * <p> |
| 6287 | * An empty list means no accessibility services except system services are allowed. Null means |
| 6288 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6289 | * |
| 6290 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6291 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6292 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6293 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6294 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6295 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6296 | if (mService != null) { |
| 6297 | try { |
| 6298 | return mService.getPermittedAccessibilityServices(admin); |
| 6299 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6300 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6301 | } |
| 6302 | } |
| 6303 | return null; |
| 6304 | } |
| 6305 | |
| 6306 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 6307 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 6308 | * |
| 6309 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6310 | * @param packageName Accessibility service package name that needs to be checked. |
| 6311 | * @param userHandle user id the admin is running as. |
| 6312 | * @return true if the accessibility service is permitted, otherwise false. |
| 6313 | * |
| 6314 | * @hide |
| 6315 | */ |
| 6316 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 6317 | @NonNull String packageName, int userHandle) { |
| 6318 | if (mService != null) { |
| 6319 | try { |
| 6320 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 6321 | userHandle); |
| 6322 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6323 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 6324 | } |
| 6325 | } |
| 6326 | return false; |
| 6327 | } |
| 6328 | |
| 6329 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6330 | * Returns the list of accessibility services permitted by the device or profiles |
| 6331 | * owners of this user. |
| 6332 | * |
| 6333 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 6334 | * it will contain the intersection of the permitted lists for any device or profile |
| 6335 | * owners that apply to this user. It will also include any system accessibility services. |
| 6336 | * |
| 6337 | * @param userId which user to check for. |
| 6338 | * @return List of accessiblity service package names. |
| 6339 | * @hide |
| 6340 | */ |
| 6341 | @SystemApi |
Eric Sandness | 5ab98de | 2018-04-03 18:12:39 +0100 | [diff] [blame] | 6342 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6343 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6344 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6345 | if (mService != null) { |
| 6346 | try { |
| 6347 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 6348 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6349 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6350 | } |
| 6351 | } |
| 6352 | return null; |
| 6353 | } |
| 6354 | |
| 6355 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6356 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 6357 | * a device owner or profile owner the restriction applies to all profiles of the user the |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6358 | * device owner or profile owner is an admin for. By default, the user can use any input method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6359 | * When zero or more packages have been added, input method that are not in the list and not |
| 6360 | * part of the system can not be enabled by the user. This method will fail if it is called for |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6361 | * a admin that is not for the foreground user or a profile of the foreground user. Any |
| 6362 | * non-system input method service that's currently enabled must be included in the list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6363 | * <p> |
| 6364 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 6365 | * be used, calling with an empty list disables all but the system's own input methods. |
| 6366 | * <p> |
| 6367 | * 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] | 6368 | * |
| 6369 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6370 | * @param packageNames List of input method package names. |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 6371 | * @return {@code true} if the operation succeeded, or {@code false} if the list didn't |
| 6372 | * contain every enabled non-system input method service. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6373 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6374 | */ |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 6375 | public boolean setPermittedInputMethods( |
| 6376 | @NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6377 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6378 | if (mService != null) { |
| 6379 | try { |
| 6380 | return mService.setPermittedInputMethods(admin, packageNames); |
| 6381 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6382 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6383 | } |
| 6384 | } |
| 6385 | return false; |
| 6386 | } |
| 6387 | |
| 6388 | |
| 6389 | /** |
| 6390 | * 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] | 6391 | * <p> |
| 6392 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 6393 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6394 | * |
| 6395 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6396 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6397 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6398 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6399 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6400 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6401 | if (mService != null) { |
| 6402 | try { |
| 6403 | return mService.getPermittedInputMethods(admin); |
| 6404 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6405 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6406 | } |
| 6407 | } |
| 6408 | return null; |
| 6409 | } |
| 6410 | |
| 6411 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 6412 | * Called by the system to check if a specific input method is disabled by admin. |
| 6413 | * |
| 6414 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6415 | * @param packageName Input method package name that needs to be checked. |
| 6416 | * @param userHandle user id the admin is running as. |
| 6417 | * @return true if the input method is permitted, otherwise false. |
| 6418 | * |
| 6419 | * @hide |
| 6420 | */ |
| 6421 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 6422 | @NonNull String packageName, int userHandle) { |
| 6423 | if (mService != null) { |
| 6424 | try { |
| 6425 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 6426 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6427 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 6428 | } |
| 6429 | } |
| 6430 | return false; |
| 6431 | } |
| 6432 | |
| 6433 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6434 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6435 | * 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] | 6436 | * |
| 6437 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 6438 | * it will contain the intersection of the permitted lists for any device or profile |
| 6439 | * owners that apply to this user. It will also include any system input methods. |
| 6440 | * |
| 6441 | * @return List of input method package names. |
| 6442 | * @hide |
| 6443 | */ |
| 6444 | @SystemApi |
Eric Sandness | 5737893 | 2018-03-27 13:22:52 +0100 | [diff] [blame] | 6445 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6446 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6447 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6448 | if (mService != null) { |
| 6449 | try { |
| 6450 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 6451 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6452 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 6453 | } |
| 6454 | } |
| 6455 | return null; |
| 6456 | } |
| 6457 | |
| 6458 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 6459 | * Called by a profile owner of a managed profile to set the packages that are allowed to use |
| 6460 | * a {@link android.service.notification.NotificationListenerService} in the primary user to |
| 6461 | * see notifications from the managed profile. By default all packages are permitted by this |
| 6462 | * policy. When zero or more packages have been added, notification listeners installed on the |
| 6463 | * primary user that are not in the list and are not part of the system won't receive events |
| 6464 | * for managed profile notifications. |
| 6465 | * <p> |
| 6466 | * Calling with a {@code null} value for the list disables the restriction so that all |
| 6467 | * notification listener services be used. Calling with an empty list disables all but the |
| 6468 | * system's own notification listeners. System notification listener services are always |
| 6469 | * available to the user. |
| 6470 | * <p> |
| 6471 | * If a device or profile owner want to stop notification listeners in their user from seeing |
| 6472 | * that user's notifications they should prevent that service from running instead (e.g. via |
| 6473 | * {@link #setApplicationHidden(ComponentName, String, boolean)}) |
| 6474 | * |
| 6475 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6476 | * @param packageList List of package names to whitelist |
| 6477 | * @return true if setting the restriction succeeded. It will fail if called outside a managed |
| 6478 | * profile |
| 6479 | * @throws SecurityException if {@code admin} is not a profile owner. |
| 6480 | * |
| 6481 | * @see android.service.notification.NotificationListenerService |
| 6482 | */ |
| 6483 | public boolean setPermittedCrossProfileNotificationListeners( |
| 6484 | @NonNull ComponentName admin, @Nullable List<String> packageList) { |
| 6485 | throwIfParentInstance("setPermittedCrossProfileNotificationListeners"); |
| 6486 | if (mService != null) { |
| 6487 | try { |
| 6488 | return mService.setPermittedCrossProfileNotificationListeners(admin, packageList); |
| 6489 | } catch (RemoteException e) { |
| 6490 | throw e.rethrowFromSystemServer(); |
| 6491 | } |
| 6492 | } |
| 6493 | return false; |
| 6494 | } |
| 6495 | |
| 6496 | /** |
| 6497 | * Returns the list of packages installed on the primary user that allowed to use a |
| 6498 | * {@link android.service.notification.NotificationListenerService} to receive |
| 6499 | * notifications from this managed profile, as set by the profile owner. |
| 6500 | * <p> |
| 6501 | * An empty list means no notification listener services except system ones are allowed. |
| 6502 | * A {@code null} return value indicates that all notification listeners are allowed. |
| 6503 | */ |
| 6504 | public @Nullable List<String> getPermittedCrossProfileNotificationListeners( |
| 6505 | @NonNull ComponentName admin) { |
| 6506 | throwIfParentInstance("getPermittedCrossProfileNotificationListeners"); |
| 6507 | if (mService != null) { |
| 6508 | try { |
| 6509 | return mService.getPermittedCrossProfileNotificationListeners(admin); |
| 6510 | } catch (RemoteException e) { |
| 6511 | throw e.rethrowFromSystemServer(); |
| 6512 | } |
| 6513 | } |
| 6514 | return null; |
| 6515 | } |
| 6516 | |
| 6517 | /** |
| 6518 | * Returns true if {@code NotificationListenerServices} from the given package are allowed to |
| 6519 | * receive events for notifications from the given user id. Can only be called by the system uid |
| 6520 | * |
| 6521 | * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List) |
| 6522 | * |
| 6523 | * @hide |
| 6524 | */ |
| 6525 | public boolean isNotificationListenerServicePermitted( |
| 6526 | @NonNull String packageName, @UserIdInt int userId) { |
| 6527 | if (mService != null) { |
| 6528 | try { |
| 6529 | return mService.isNotificationListenerServicePermitted(packageName, userId); |
| 6530 | } catch (RemoteException e) { |
| 6531 | throw e.rethrowFromSystemServer(); |
| 6532 | } |
| 6533 | } |
| 6534 | return true; |
| 6535 | } |
| 6536 | |
| 6537 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6538 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 6539 | * function can be called by a device owner or by a delegate given the |
| 6540 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 6541 | * <p> |
| 6542 | * Please note that packages returned in this method are not automatically pre-cached. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6543 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6544 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6545 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6546 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6547 | * @see #setDelegatedScopes |
| 6548 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6549 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6550 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6551 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6552 | if (mService != null) { |
| 6553 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6554 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6555 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6556 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6557 | } |
| 6558 | } |
| 6559 | return null; |
| 6560 | } |
| 6561 | |
| 6562 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6563 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 6564 | * function can be called by a device owner or by a delegate given the |
| 6565 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6566 | * |
| 6567 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 6568 | * automatically pre-cached.</p> |
| 6569 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6570 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6571 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6572 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6573 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6574 | * @see #setDelegatedScopes |
| 6575 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6576 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6577 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6578 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6579 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6580 | if (mService != null) { |
| 6581 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6582 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6583 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6584 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6585 | } |
| 6586 | } |
| 6587 | } |
| 6588 | |
| 6589 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6590 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 6591 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 6592 | * created. If you need to persist an identifier for this user, use |
| 6593 | * {@link UserManager#getSerialNumberForUser}. |
| 6594 | * |
| 6595 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6596 | * @param name the user's name |
| 6597 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6598 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6599 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6600 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6601 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 6602 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6603 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6604 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6605 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6606 | return null; |
| 6607 | } |
| 6608 | |
| 6609 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 6610 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 6611 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 6612 | * created. If you need to persist an identifier for this user, use |
| 6613 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 6614 | * immediately. |
| 6615 | * |
| 6616 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 6617 | * as registered as an active admin on the new user. The profile owner package will be |
| 6618 | * installed on the new user if it already is installed on the device. |
| 6619 | * |
| 6620 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 6621 | * profileOwnerComponent when onEnable is called. |
| 6622 | * |
| 6623 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6624 | * @param name the user's name |
| 6625 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 6626 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 6627 | * the user. |
| 6628 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 6629 | * on the new user. |
| 6630 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6631 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6632 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6633 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6634 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 6635 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 6636 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6637 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6638 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6639 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 6640 | return null; |
| 6641 | } |
| 6642 | |
| 6643 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6644 | * 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] | 6645 | */ |
| 6646 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 6647 | |
| 6648 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 6649 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
Alex Chau | 6badae6 | 2017-10-27 17:46:16 +0100 | [diff] [blame] | 6650 | * ephemeral. Ephemeral users will be removed after switching to another user or rebooting the |
| 6651 | * device. |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 6652 | */ |
| 6653 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 6654 | |
| 6655 | /** |
Christine Franks | 361b825 | 2017-06-23 18:12:46 -0700 | [diff] [blame] | 6656 | * Flag used by {@link #createAndManageUser} to specify that the user should be created as a |
| 6657 | * demo user. |
| 6658 | * @hide |
| 6659 | */ |
| 6660 | public static final int MAKE_USER_DEMO = 0x0004; |
| 6661 | |
| 6662 | /** |
Alex Chau | b6a9f94 | 2017-11-07 11:28:56 +0800 | [diff] [blame] | 6663 | * Flag used by {@link #createAndManageUser} to specify that the newly created user should skip |
| 6664 | * the disabling of system apps during provisioning. |
| 6665 | */ |
| 6666 | public static final int LEAVE_ALL_SYSTEM_APPS_ENABLED = 0x0010; |
| 6667 | |
| 6668 | /** |
Benjamin Franz | 77c94a9 | 2017-08-09 14:16:03 +0100 | [diff] [blame] | 6669 | * @hide |
| 6670 | */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 6671 | @IntDef(flag = true, prefix = { "SKIP_", "MAKE_USER_", "START_", "LEAVE_" }, value = { |
| 6672 | SKIP_SETUP_WIZARD, |
| 6673 | MAKE_USER_EPHEMERAL, |
| 6674 | MAKE_USER_DEMO, |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 6675 | LEAVE_ALL_SYSTEM_APPS_ENABLED |
| 6676 | }) |
Benjamin Franz | 77c94a9 | 2017-08-09 14:16:03 +0100 | [diff] [blame] | 6677 | @Retention(RetentionPolicy.SOURCE) |
| 6678 | public @interface CreateAndManageUserFlags {} |
| 6679 | |
| 6680 | |
| 6681 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6682 | * Called by a device owner to create a user with the specified name and a given component of |
| 6683 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 6684 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 6685 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 6686 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6687 | * <p> |
| 6688 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 6689 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 6690 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 6691 | * on the new user. |
| 6692 | * <p> |
| 6693 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 6694 | * for the first time. Then the extras will be passed to the admin when onEnable is called. |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 6695 | * <p>From {@link android.os.Build.VERSION_CODES#P} onwards, if targeting |
| 6696 | * {@link android.os.Build.VERSION_CODES#P}, throws {@link UserOperationException} instead of |
| 6697 | * returning {@code null} on failure. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6698 | * |
| 6699 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6700 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6701 | * @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] | 6702 | * same package as admin, otherwise no user is created and an |
| 6703 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6704 | * @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] | 6705 | * user. |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6706 | * @param flags {@link #SKIP_SETUP_WIZARD}, {@link #MAKE_USER_EPHEMERAL} and |
| 6707 | * {@link #LEAVE_ALL_SYSTEM_APPS_ENABLED} are supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6708 | * @see UserHandle |
| 6709 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6710 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6711 | * @throws SecurityException if {@code admin} is not a device owner. |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 6712 | * @throws UserOperationException if the user could not be created and the calling app is |
| 6713 | * targeting {@link android.os.Build.VERSION_CODES#P} and running on |
| 6714 | * {@link android.os.Build.VERSION_CODES#P}. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6715 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6716 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 6717 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6718 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
Benjamin Franz | 77c94a9 | 2017-08-09 14:16:03 +0100 | [diff] [blame] | 6719 | @CreateAndManageUserFlags int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6720 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6721 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6722 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 6723 | } catch (ServiceSpecificException e) { |
| 6724 | throw new UserOperationException(e.getMessage(), e.errorCode); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6725 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6726 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6727 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6728 | } |
| 6729 | |
| 6730 | /** |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6731 | * Called by a device owner to remove a user/profile and all associated data. The primary user |
| 6732 | * can not be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6733 | * |
| 6734 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6735 | * @param userHandle the user to remove. |
| 6736 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6737 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6738 | */ |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6739 | public boolean removeUser(@NonNull ComponentName admin, @NonNull UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6740 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6741 | try { |
| 6742 | return mService.removeUser(admin, userHandle); |
| 6743 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6744 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6745 | } |
| 6746 | } |
| 6747 | |
| 6748 | /** |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6749 | * Called by a device owner to switch the specified secondary user to the foreground. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6750 | * |
| 6751 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6752 | * @param userHandle the user to switch to; null will switch to primary. |
| 6753 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6754 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6755 | * @see Intent#ACTION_USER_FOREGROUND |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6756 | * @see #getSecondaryUsers(ComponentName) |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6757 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6758 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6759 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6760 | try { |
| 6761 | return mService.switchUser(admin, userHandle); |
| 6762 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6763 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6764 | } |
| 6765 | } |
| 6766 | |
| 6767 | /** |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6768 | * Called by a device owner to start the specified secondary user in background. |
| 6769 | * |
| 6770 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Alex Chau | 596c288 | 2018-01-29 14:39:37 +0000 | [diff] [blame] | 6771 | * @param userHandle the user to be started in background. |
| 6772 | * @return one of the following result codes: |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 6773 | * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN}, |
| 6774 | * {@link UserManager#USER_OPERATION_SUCCESS}, |
| 6775 | * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE}, |
| 6776 | * {@link UserManager#USER_OPERATION_ERROR_MAX_RUNNING_USERS}, |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6777 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6778 | * @see #getSecondaryUsers(ComponentName) |
| 6779 | */ |
Alex Chau | 596c288 | 2018-01-29 14:39:37 +0000 | [diff] [blame] | 6780 | public @UserOperationResult int startUserInBackground( |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6781 | @NonNull ComponentName admin, @NonNull UserHandle userHandle) { |
| 6782 | throwIfParentInstance("startUserInBackground"); |
| 6783 | try { |
| 6784 | return mService.startUserInBackground(admin, userHandle); |
| 6785 | } catch (RemoteException re) { |
| 6786 | throw re.rethrowFromSystemServer(); |
| 6787 | } |
| 6788 | } |
| 6789 | |
| 6790 | /** |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6791 | * Called by a device owner to stop the specified secondary user. |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6792 | * |
| 6793 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6794 | * @param userHandle the user to be stopped. |
Alex Chau | 596c288 | 2018-01-29 14:39:37 +0000 | [diff] [blame] | 6795 | * @return one of the following result codes: |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 6796 | * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN}, |
| 6797 | * {@link UserManager#USER_OPERATION_SUCCESS}, |
| 6798 | * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE}, |
| 6799 | * {@link UserManager#USER_OPERATION_ERROR_CURRENT_USER} |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6800 | * @throws SecurityException if {@code admin} is not a device owner. |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6801 | * @see #getSecondaryUsers(ComponentName) |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6802 | */ |
Alex Chau | 596c288 | 2018-01-29 14:39:37 +0000 | [diff] [blame] | 6803 | public @UserOperationResult int stopUser( |
| 6804 | @NonNull ComponentName admin, @NonNull UserHandle userHandle) { |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6805 | throwIfParentInstance("stopUser"); |
| 6806 | try { |
| 6807 | return mService.stopUser(admin, userHandle); |
| 6808 | } catch (RemoteException re) { |
| 6809 | throw re.rethrowFromSystemServer(); |
| 6810 | } |
| 6811 | } |
| 6812 | |
| 6813 | /** |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6814 | * Called by a profile owner of secondary user that is affiliated with the device to stop the |
| 6815 | * calling user and switch back to primary. |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6816 | * |
| 6817 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Alex Chau | 596c288 | 2018-01-29 14:39:37 +0000 | [diff] [blame] | 6818 | * @return one of the following result codes: |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 6819 | * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN}, |
| 6820 | * {@link UserManager#USER_OPERATION_SUCCESS}, |
| 6821 | * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE}, |
| 6822 | * {@link UserManager#USER_OPERATION_ERROR_CURRENT_USER} |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 6823 | * @throws SecurityException if {@code admin} is not a profile owner affiliated with the device. |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6824 | * @see #getSecondaryUsers(ComponentName) |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6825 | */ |
Alex Chau | 596c288 | 2018-01-29 14:39:37 +0000 | [diff] [blame] | 6826 | public @UserOperationResult int logoutUser(@NonNull ComponentName admin) { |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6827 | throwIfParentInstance("logoutUser"); |
| 6828 | try { |
| 6829 | return mService.logoutUser(admin); |
| 6830 | } catch (RemoteException re) { |
| 6831 | throw re.rethrowFromSystemServer(); |
| 6832 | } |
| 6833 | } |
| 6834 | |
| 6835 | /** |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6836 | * Called by a device owner to list all secondary users on the device. Managed profiles are not |
| 6837 | * considered as secondary users. |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6838 | * <p> Used for various user management APIs, including {@link #switchUser}, {@link #removeUser} |
| 6839 | * and {@link #stopUser}. |
| 6840 | * |
| 6841 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6842 | * @return list of other {@link UserHandle}s on the device. |
| 6843 | * @throws SecurityException if {@code admin} is not a device owner. |
Alex Chau | b6ef869 | 2018-01-09 14:16:36 +0000 | [diff] [blame] | 6844 | * @see #removeUser(ComponentName, UserHandle) |
| 6845 | * @see #switchUser(ComponentName, UserHandle) |
| 6846 | * @see #startUserInBackground(ComponentName, UserHandle) |
| 6847 | * @see #stopUser(ComponentName, UserHandle) |
Alex Chau | af9bb8d | 2017-12-06 14:38:25 +0000 | [diff] [blame] | 6848 | */ |
| 6849 | public List<UserHandle> getSecondaryUsers(@NonNull ComponentName admin) { |
| 6850 | throwIfParentInstance("getSecondaryUsers"); |
| 6851 | try { |
| 6852 | return mService.getSecondaryUsers(admin); |
| 6853 | } catch (RemoteException re) { |
| 6854 | throw re.rethrowFromSystemServer(); |
| 6855 | } |
| 6856 | } |
| 6857 | |
| 6858 | /** |
Alex Chau | 8d6e18c | 2017-12-08 18:11:27 +0000 | [diff] [blame] | 6859 | * Checks if the profile owner is running in an ephemeral user. |
| 6860 | * |
| 6861 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6862 | * @return whether the profile owner is running in an ephemeral user. |
| 6863 | */ |
| 6864 | public boolean isEphemeralUser(@NonNull ComponentName admin) { |
| 6865 | throwIfParentInstance("isEphemeralUser"); |
| 6866 | try { |
| 6867 | return mService.isEphemeralUser(admin); |
| 6868 | } catch (RemoteException re) { |
| 6869 | throw re.rethrowFromSystemServer(); |
| 6870 | } |
| 6871 | } |
| 6872 | |
| 6873 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6874 | * Retrieves the application restrictions for a given target application running in the calling |
| 6875 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6876 | * <p> |
| 6877 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6878 | * application restrictions via {@link #setDelegatedScopes} with the |
| 6879 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6880 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6881 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 6882 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6883 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6884 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6885 | * @param packageName The name of the package to fetch restricted settings of. |
| 6886 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6887 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 6888 | * {@link Bundle} if no restrictions have been set. |
| 6889 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6890 | * @see #setDelegatedScopes |
| 6891 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6892 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6893 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6894 | public @NonNull Bundle getApplicationRestrictions( |
| 6895 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6896 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6897 | if (mService != null) { |
| 6898 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6899 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 6900 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6901 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6902 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6903 | } |
| 6904 | } |
| 6905 | return null; |
| 6906 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6907 | |
| 6908 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6909 | * 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] | 6910 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6911 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6912 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6913 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6914 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6915 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6916 | * for the list of keys. |
| 6917 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6918 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6919 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6920 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6921 | if (mService != null) { |
| 6922 | try { |
| 6923 | mService.setUserRestriction(admin, key, true); |
| 6924 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6925 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6926 | } |
| 6927 | } |
| 6928 | } |
| 6929 | |
| 6930 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6931 | * 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] | 6932 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6933 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6934 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6935 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6936 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6937 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6938 | * for the list of keys. |
| 6939 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6940 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6941 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6942 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6943 | if (mService != null) { |
| 6944 | try { |
| 6945 | mService.setUserRestriction(admin, key, false); |
| 6946 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6947 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6948 | } |
| 6949 | } |
| 6950 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 6951 | |
| 6952 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6953 | * Called by a profile or device owner to get user restrictions set with |
| 6954 | * {@link #addUserRestriction(ComponentName, String)}. |
| 6955 | * <p> |
| 6956 | * 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] | 6957 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6958 | * {@link UserManager#getUserRestrictions()}. |
| 6959 | * |
| 6960 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6961 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6962 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6963 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6964 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6965 | Bundle ret = null; |
| 6966 | if (mService != null) { |
| 6967 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 6968 | ret = mService.getUserRestrictions(admin); |
| 6969 | } catch (RemoteException e) { |
| 6970 | throw e.rethrowFromSystemServer(); |
| 6971 | } |
| 6972 | } |
| 6973 | return ret == null ? new Bundle() : ret; |
| 6974 | } |
| 6975 | |
| 6976 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6977 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 6978 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 6979 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 6980 | * was disabled by an admin, and include a link for more information. The default content of |
| 6981 | * the dialog can be changed by the restricting admin via |
| 6982 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 6983 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 6984 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 6985 | * user restriction from {@link UserManager}, e.g. |
| 6986 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
Lenka Trochtova | 27fd821 | 2018-04-10 11:01:58 +0200 | [diff] [blame] | 6987 | * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6988 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 6989 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 6990 | */ |
| 6991 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 6992 | throwIfParentInstance("createAdminSupportIntent"); |
| 6993 | if (mService != null) { |
| 6994 | try { |
| 6995 | return mService.createAdminSupportIntent(restriction); |
| 6996 | } catch (RemoteException e) { |
| 6997 | throw e.rethrowFromSystemServer(); |
| 6998 | } |
| 6999 | } |
| 7000 | return null; |
| 7001 | } |
| 7002 | |
| 7003 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7004 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 7005 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 7006 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 7007 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7008 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7009 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 7010 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7011 | * @param packageName The name of the package to hide or unhide. |
| 7012 | * @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] | 7013 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7014 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7015 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7016 | * @see #setDelegatedScopes |
| 7017 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7018 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7019 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7020 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7021 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7022 | if (mService != null) { |
| 7023 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7024 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 7025 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7026 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7027 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7028 | } |
| 7029 | } |
| 7030 | return false; |
| 7031 | } |
| 7032 | |
| 7033 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7034 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 7035 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 7036 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7037 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7038 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 7039 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7040 | * @param packageName The name of the package to retrieve the hidden status of. |
| 7041 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7042 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7043 | * @see #setDelegatedScopes |
| 7044 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7045 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7046 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7047 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7048 | if (mService != null) { |
| 7049 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7050 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7051 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7052 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 7053 | } |
| 7054 | } |
| 7055 | return false; |
| 7056 | } |
| 7057 | |
| 7058 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7059 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 7060 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 7061 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7062 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7063 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 7064 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 7065 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7066 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7067 | * @see #setDelegatedScopes |
| 7068 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7069 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7070 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7071 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7072 | if (mService != null) { |
| 7073 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7074 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7075 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7076 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7077 | } |
| 7078 | } |
| 7079 | } |
| 7080 | |
| 7081 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7082 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 7083 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 7084 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7085 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7086 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 7087 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7088 | * @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] | 7089 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7090 | * @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] | 7091 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7092 | * @see #setDelegatedScopes |
| 7093 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7094 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7095 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7096 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7097 | if (mService != null) { |
| 7098 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7099 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7100 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7101 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 7102 | } |
| 7103 | } |
| 7104 | return 0; |
| 7105 | } |
| 7106 | |
| 7107 | /** |
Alex Chau | 5343fcb | 2017-12-05 16:49:19 +0000 | [diff] [blame] | 7108 | * Install an existing package that has been installed in another user, or has been kept after |
| 7109 | * removal via {@link #setKeepUninstalledPackages}. |
| 7110 | * This function can be called by a device owner, profile owner or a delegate given |
| 7111 | * the {@link #DELEGATION_INSTALL_EXISTING_PACKAGE} scope via {@link #setDelegatedScopes}. |
| 7112 | * When called in a secondary user or managed profile, the user/profile must be affiliated with |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 7113 | * the device. See {@link #isAffiliatedUser}. |
Alex Chau | 5343fcb | 2017-12-05 16:49:19 +0000 | [diff] [blame] | 7114 | * |
| 7115 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7116 | * @param packageName The package to be installed in the calling profile. |
| 7117 | * @return {@code true} if the app is installed; {@code false} otherwise. |
| 7118 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 7119 | * an affiliated user or profile. |
| 7120 | * @see #setKeepUninstalledPackages |
| 7121 | * @see #setDelegatedScopes |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 7122 | * @see #isAffiliatedUser |
Alex Chau | 5343fcb | 2017-12-05 16:49:19 +0000 | [diff] [blame] | 7123 | * @see #DELEGATION_PACKAGE_ACCESS |
| 7124 | */ |
| 7125 | public boolean installExistingPackage(@NonNull ComponentName admin, String packageName) { |
| 7126 | throwIfParentInstance("installExistingPackage"); |
| 7127 | if (mService != null) { |
| 7128 | try { |
| 7129 | return mService.installExistingPackage(admin, mContext.getPackageName(), |
| 7130 | packageName); |
| 7131 | } catch (RemoteException e) { |
| 7132 | throw e.rethrowFromSystemServer(); |
| 7133 | } |
| 7134 | } |
| 7135 | return false; |
| 7136 | } |
| 7137 | |
| 7138 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 7139 | * Called by a device owner or profile owner to disable account management for a specific type |
| 7140 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7141 | * <p> |
| 7142 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 7143 | * exception will be thrown. |
| 7144 | * <p> |
| 7145 | * When account management is disabled for an account type, adding or removing an account of |
| 7146 | * that type will not be possible. |
| 7147 | * <p> |
| 7148 | * 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] | 7149 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 7150 | * management for a specific type is disabled. |
| 7151 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 7152 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7153 | * @param accountType For which account management is disabled or enabled. |
| 7154 | * @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] | 7155 | * enabled (false). |
| 7156 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 7157 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7158 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 7159 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7160 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 7161 | if (mService != null) { |
| 7162 | try { |
| 7163 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 7164 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7165 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 7166 | } |
| 7167 | } |
| 7168 | } |
| 7169 | |
| 7170 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 7171 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 7172 | * |
| 7173 | * <p> Account management can be disabled/enabled by calling |
| 7174 | * {@link #setAccountManagementDisabled}. |
| 7175 | * |
| 7176 | * @return a list of account types for which account management has been disabled. |
| 7177 | * |
| 7178 | * @see #setAccountManagementDisabled |
| 7179 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7180 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7181 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 7182 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | /** |
| 7186 | * @see #getAccountTypesWithManagementDisabled() |
| 7187 | * @hide |
| 7188 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7189 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 7190 | if (mService != null) { |
| 7191 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 7192 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 7193 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7194 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 7195 | } |
| 7196 | } |
| 7197 | |
| 7198 | return null; |
| 7199 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7200 | |
| 7201 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 7202 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7203 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 7204 | * Any packages that share uid with an allowed package will also be allowed to activate lock |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7205 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 7206 | * package list results in locked tasks belonging to those packages to be finished. |
| 7207 | * <p> |
Jason Parks | 3c13b64 | 2017-11-28 15:39:43 -0600 | [diff] [blame] | 7208 | * This function can only be called by the device owner, a profile owner of an affiliated user |
| 7209 | * or profile, or the profile owner when no device owner is set. See {@link #isAffiliatedUser}. |
| 7210 | * Any package set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 7211 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 7212 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 7213 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Parks | 3c13b64 | 2017-11-28 15:39:43 -0600 | [diff] [blame] | 7214 | * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an |
| 7215 | * affiliated user or profile, or the profile owner when no device owner is set. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 7216 | * @see #isAffiliatedUser |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 7217 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 7218 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 7219 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 7220 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7221 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 7222 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 7223 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7224 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7225 | if (mService != null) { |
| 7226 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 7227 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7228 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7229 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7230 | } |
| 7231 | } |
| 7232 | } |
| 7233 | |
| 7234 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 7235 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 7236 | * |
Jason Parks | 3c13b64 | 2017-11-28 15:39:43 -0600 | [diff] [blame] | 7237 | * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an |
| 7238 | * affiliated user or profile, or the profile owner when no device owner is set. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 7239 | * @see #isAffiliatedUser |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 7240 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7241 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7242 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7243 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7244 | if (mService != null) { |
| 7245 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 7246 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7247 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7248 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7249 | } |
| 7250 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 7251 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7252 | } |
| 7253 | |
| 7254 | /** |
| 7255 | * This function lets the caller know whether the given component is allowed to start the |
| 7256 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 7257 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7258 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 7259 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7260 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7261 | if (mService != null) { |
| 7262 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 7263 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7264 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7265 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 7266 | } |
| 7267 | } |
| 7268 | return false; |
| 7269 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7270 | |
| 7271 | /** |
Benjamin Franz | 78ae106 | 2018-03-26 11:01:32 +0100 | [diff] [blame] | 7272 | * Sets which system features are enabled when the device runs in lock task mode. This method |
| 7273 | * doesn't affect the features when lock task mode is inactive. Any system features not included |
| 7274 | * in {@code flags} are implicitly disabled when calling this method. By default, only |
| 7275 | * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS} is enabled—all the other features are disabled. To |
| 7276 | * disable the global actions dialog, call this method omitting |
| 7277 | * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS}. |
| 7278 | * |
| 7279 | * <p>This method can only be called by the device owner, a profile owner of an affiliated |
| 7280 | * user or profile, or the profile owner when no device owner is set. See |
| 7281 | * {@link #isAffiliatedUser}. |
| 7282 | * Any features set using this method are cleared if the user becomes unaffiliated. |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 7283 | * |
| 7284 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | 78ae106 | 2018-03-26 11:01:32 +0100 | [diff] [blame] | 7285 | * @param flags The system features enabled during lock task mode. |
Jason Parks | 3c13b64 | 2017-11-28 15:39:43 -0600 | [diff] [blame] | 7286 | * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an |
| 7287 | * affiliated user or profile, or the profile owner when no device owner is set. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 7288 | * @see #isAffiliatedUser |
Benjamin Franz | 78ae106 | 2018-03-26 11:01:32 +0100 | [diff] [blame] | 7289 | **/ |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 7290 | public void setLockTaskFeatures(@NonNull ComponentName admin, @LockTaskFeature int flags) { |
| 7291 | throwIfParentInstance("setLockTaskFeatures"); |
| 7292 | if (mService != null) { |
| 7293 | try { |
| 7294 | mService.setLockTaskFeatures(admin, flags); |
| 7295 | } catch (RemoteException e) { |
| 7296 | throw e.rethrowFromSystemServer(); |
| 7297 | } |
| 7298 | } |
| 7299 | } |
| 7300 | |
| 7301 | /** |
| 7302 | * Gets which system features are enabled for LockTask mode. |
| 7303 | * |
| 7304 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7305 | * @return bitfield of flags. See {@link #setLockTaskFeatures(ComponentName, int)} for a list. |
Jason Parks | 3c13b64 | 2017-11-28 15:39:43 -0600 | [diff] [blame] | 7306 | * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an |
| 7307 | * affiliated user or profile, or the profile owner when no device owner is set. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 7308 | * @see #isAffiliatedUser |
| 7309 | * @see #setLockTaskFeatures |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 7310 | */ |
| 7311 | public @LockTaskFeature int getLockTaskFeatures(@NonNull ComponentName admin) { |
| 7312 | throwIfParentInstance("getLockTaskFeatures"); |
| 7313 | if (mService != null) { |
| 7314 | try { |
| 7315 | return mService.getLockTaskFeatures(admin); |
| 7316 | } catch (RemoteException e) { |
| 7317 | throw e.rethrowFromSystemServer(); |
| 7318 | } |
| 7319 | } |
| 7320 | return 0; |
| 7321 | } |
| 7322 | |
| 7323 | /** |
yuemingw | 0de748d | 2017-11-15 19:22:27 +0000 | [diff] [blame] | 7324 | * Called by device owner to update {@link android.provider.Settings.Global} settings. |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7325 | * Validation that the value of the setting is in the correct form for the setting type should |
| 7326 | * be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7327 | * <p> |
| 7328 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 7329 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7330 | * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li> |
| 7331 | * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li> |
| 7332 | * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li> |
| 7333 | * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li> |
| 7334 | * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
| 7335 | * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li> |
| 7336 | * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only |
| 7337 | * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7338 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7339 | * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This |
| 7340 | * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 7341 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7342 | * <p> |
| 7343 | * 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] | 7344 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7345 | * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7346 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 7347 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7348 | * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 7349 | * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7350 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7351 | * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li> |
| 7352 | * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7353 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 7354 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7355 | * |
| 7356 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7357 | * @param setting The name of the setting to update. |
| 7358 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7359 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7360 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7361 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7362 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7363 | if (mService != null) { |
| 7364 | try { |
| 7365 | mService.setGlobalSetting(admin, setting, value); |
| 7366 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7367 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7368 | } |
| 7369 | } |
| 7370 | } |
| 7371 | |
yuemingw | 93ffce6 | 2018-02-21 16:20:14 +0000 | [diff] [blame] | 7372 | /** @hide */ |
| 7373 | @StringDef({ |
| 7374 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 7375 | Settings.System.SCREEN_BRIGHTNESS, |
| 7376 | Settings.System.SCREEN_OFF_TIMEOUT |
| 7377 | }) |
| 7378 | @Retention(RetentionPolicy.SOURCE) |
| 7379 | public @interface SystemSettingsWhitelist {} |
| 7380 | |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7381 | /** |
yuemingw | c0281f1 | 2018-03-28 15:58:49 +0100 | [diff] [blame] | 7382 | * Called by a device or profile owner to update {@link android.provider.Settings.System} |
| 7383 | * settings. Validation that the value of the setting is in the correct form for the setting |
| 7384 | * type should be performed by the caller. |
yuemingw | 0de748d | 2017-11-15 19:22:27 +0000 | [diff] [blame] | 7385 | * <p> |
yuemingw | c0281f1 | 2018-03-28 15:58:49 +0100 | [diff] [blame] | 7386 | * The settings that can be updated by a device owner or profile owner of secondary user with |
| 7387 | * this method are: |
yuemingw | 0de748d | 2017-11-15 19:22:27 +0000 | [diff] [blame] | 7388 | * <ul> |
| 7389 | * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS}</li> |
| 7390 | * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS_MODE}</li> |
| 7391 | * <li>{@link android.provider.Settings.System#SCREEN_OFF_TIMEOUT}</li> |
| 7392 | * </ul> |
| 7393 | * <p> |
| 7394 | * |
| 7395 | * @see android.provider.Settings.System#SCREEN_OFF_TIMEOUT |
| 7396 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7397 | * @param setting The name of the setting to update. |
| 7398 | * @param value The value to update the setting to. |
yuemingw | c0281f1 | 2018-03-28 15:58:49 +0100 | [diff] [blame] | 7399 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
yuemingw | 0de748d | 2017-11-15 19:22:27 +0000 | [diff] [blame] | 7400 | */ |
yuemingw | 93ffce6 | 2018-02-21 16:20:14 +0000 | [diff] [blame] | 7401 | public void setSystemSetting(@NonNull ComponentName admin, |
| 7402 | @NonNull @SystemSettingsWhitelist String setting, String value) { |
yuemingw | 0de748d | 2017-11-15 19:22:27 +0000 | [diff] [blame] | 7403 | throwIfParentInstance("setSystemSetting"); |
| 7404 | if (mService != null) { |
| 7405 | try { |
| 7406 | mService.setSystemSetting(admin, setting, value); |
| 7407 | } catch (RemoteException e) { |
| 7408 | throw e.rethrowFromSystemServer(); |
| 7409 | } |
| 7410 | } |
| 7411 | } |
| 7412 | |
| 7413 | /** |
yuemingw | e43cdf7 | 2017-10-12 16:52:11 +0100 | [diff] [blame] | 7414 | * Called by device owner to set the system wall clock time. This only takes effect if called |
| 7415 | * when {@link android.provider.Settings.Global#AUTO_TIME} is 0, otherwise {@code false} will be |
| 7416 | * returned. |
| 7417 | * |
| 7418 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with |
| 7419 | * @param millis time in milliseconds since the Epoch |
| 7420 | * @return {@code true} if set time succeeded, {@code false} otherwise. |
| 7421 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7422 | */ |
| 7423 | public boolean setTime(@NonNull ComponentName admin, long millis) { |
| 7424 | throwIfParentInstance("setTime"); |
| 7425 | if (mService != null) { |
| 7426 | try { |
| 7427 | return mService.setTime(admin, millis); |
| 7428 | } catch (RemoteException e) { |
| 7429 | throw e.rethrowFromSystemServer(); |
| 7430 | } |
| 7431 | } |
| 7432 | return false; |
| 7433 | } |
| 7434 | |
| 7435 | /** |
| 7436 | * Called by device owner to set the system's persistent default time zone. This only takes |
| 7437 | * effect if called when {@link android.provider.Settings.Global#AUTO_TIME_ZONE} is 0, otherwise |
| 7438 | * {@code false} will be returned. |
| 7439 | * |
| 7440 | * @see android.app.AlarmManager#setTimeZone(String) |
| 7441 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with |
| 7442 | * @param timeZone one of the Olson ids from the list returned by |
| 7443 | * {@link java.util.TimeZone#getAvailableIDs} |
| 7444 | * @return {@code true} if set timezone succeeded, {@code false} otherwise. |
| 7445 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7446 | */ |
| 7447 | public boolean setTimeZone(@NonNull ComponentName admin, String timeZone) { |
| 7448 | throwIfParentInstance("setTimeZone"); |
| 7449 | if (mService != null) { |
| 7450 | try { |
| 7451 | return mService.setTimeZone(admin, timeZone); |
| 7452 | } catch (RemoteException e) { |
| 7453 | throw e.rethrowFromSystemServer(); |
| 7454 | } |
| 7455 | } |
| 7456 | return false; |
| 7457 | } |
| 7458 | |
| 7459 | /** |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7460 | * Called by profile or device owners to update {@link android.provider.Settings.Secure} |
| 7461 | * settings. Validation that the value of the setting is in the correct form for the setting |
| 7462 | * type should be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7463 | * <p> |
| 7464 | * 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] | 7465 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7466 | * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
| 7467 | * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 7468 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7469 | * <p> |
| 7470 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 7471 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 7472 | * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 7473 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7474 | * |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 7475 | * <strong>Note: Starting from Android O, apps should no longer call this method with the |
| 7476 | * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is |
| 7477 | * deprecated. Instead, device owners or profile owners should use the restriction |
| 7478 | * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
| 7479 | * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method |
| 7480 | * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, |
| 7481 | * an {@link UnsupportedOperationException} is thrown. |
| 7482 | * </strong> |
| 7483 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7484 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7485 | * @param setting The name of the setting to update. |
| 7486 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7487 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7488 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7489 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7490 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7491 | if (mService != null) { |
| 7492 | try { |
| 7493 | mService.setSecureSetting(admin, setting, value); |
| 7494 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7495 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 7496 | } |
| 7497 | } |
| 7498 | } |
| 7499 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 7500 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7501 | * Designates a specific service component as the provider for making permission requests of a |
| 7502 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 7503 | * <p/> |
| 7504 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7505 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 7506 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 7507 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7508 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 7509 | * provider previously assigned. |
| 7510 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 7511 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7512 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 7513 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7514 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 7515 | if (mService != null) { |
| 7516 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 7517 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 7518 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7519 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 7520 | } |
| 7521 | } |
| 7522 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7523 | |
| 7524 | /** |
| 7525 | * 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] | 7526 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7527 | * |
| 7528 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7529 | * @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] | 7530 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7531 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7532 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7533 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7534 | if (mService != null) { |
| 7535 | try { |
| 7536 | mService.setMasterVolumeMuted(admin, on); |
| 7537 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7538 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7539 | } |
| 7540 | } |
| 7541 | } |
| 7542 | |
| 7543 | /** |
| 7544 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 7545 | * |
| 7546 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7547 | * @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] | 7548 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7549 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7550 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7551 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7552 | if (mService != null) { |
| 7553 | try { |
| 7554 | return mService.isMasterVolumeMuted(admin); |
| 7555 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7556 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 7557 | } |
| 7558 | } |
| 7559 | return false; |
| 7560 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7561 | |
| 7562 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 7563 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 7564 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 7565 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7566 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 7567 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 7568 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7569 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 7570 | * @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] | 7571 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 7572 | * @see #setDelegatedScopes |
| 7573 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7574 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 7575 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 7576 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7577 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7578 | if (mService != null) { |
| 7579 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 7580 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 7581 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7582 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7583 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7584 | } |
| 7585 | } |
| 7586 | } |
| 7587 | |
| 7588 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 7589 | * 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] | 7590 | * 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] | 7591 | * <p> |
| 7592 | * <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] | 7593 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 7594 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 7595 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7596 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7597 | * @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] | 7598 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7599 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 7600 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7601 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7602 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7603 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7604 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7605 | if (mService != null) { |
| 7606 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 7607 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7608 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7609 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 7610 | } |
| 7611 | } |
| 7612 | return false; |
| 7613 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7614 | |
| 7615 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7616 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 7617 | * package to be available in the parent profile. As a result the user will be able to add |
| 7618 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 7619 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 7620 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7621 | * <p> |
| 7622 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7623 | * |
| 7624 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7625 | * @param packageName The package from which widget providers are white-listed. |
| 7626 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7627 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7628 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 7629 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 7630 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7631 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7632 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7633 | if (mService != null) { |
| 7634 | try { |
| 7635 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 7636 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7637 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7638 | } |
| 7639 | } |
| 7640 | return false; |
| 7641 | } |
| 7642 | |
| 7643 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 7644 | * 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] | 7645 | * package to be available in the parent profile. For this method to take effect the package |
| 7646 | * should have been added via |
| 7647 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7648 | * <p> |
| 7649 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7650 | * |
| 7651 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7652 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7653 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7654 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7655 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 7656 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 7657 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 7658 | public boolean removeCrossProfileWidgetProvider( |
| 7659 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7660 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7661 | if (mService != null) { |
| 7662 | try { |
| 7663 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 7664 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7665 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7666 | } |
| 7667 | } |
| 7668 | return false; |
| 7669 | } |
| 7670 | |
| 7671 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 7672 | * 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] | 7673 | * available in the parent profile. |
| 7674 | * |
| 7675 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7676 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7677 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 7678 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7679 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7680 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7681 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7682 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7683 | if (mService != null) { |
| 7684 | try { |
| 7685 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 7686 | if (providers != null) { |
| 7687 | return providers; |
| 7688 | } |
| 7689 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7690 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 7691 | } |
| 7692 | } |
| 7693 | return Collections.emptyList(); |
| 7694 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 7695 | |
| 7696 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 7697 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 7698 | * |
| 7699 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7700 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7701 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 7702 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7703 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7704 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 7705 | try { |
| 7706 | mService.setUserIcon(admin, icon); |
| 7707 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7708 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 7709 | } |
| 7710 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 7711 | |
| 7712 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 7713 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 7714 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 29b9a7d | 2018-01-11 09:24:02 +0000 | [diff] [blame] | 7715 | * <p> |
| 7716 | * If the supplied system update policy has freeze periods set but the freeze periods do not |
| 7717 | * meet 90-day maximum length or 60-day minimum separation requirement set out in |
| 7718 | * {@link SystemUpdatePolicy#setFreezePeriods}, |
| 7719 | * {@link SystemUpdatePolicy.ValidationFailedException} will the thrown. Note that the system |
| 7720 | * keeps a record of freeze periods the device experienced previously, and combines them with |
| 7721 | * the new freeze periods to be set when checking the maximum freeze length and minimum freeze |
| 7722 | * separation constraints. As a result, freeze periods that passed validation during |
| 7723 | * {@link SystemUpdatePolicy#setFreezePeriods} might fail the additional checks here due to |
| 7724 | * the freeze period history. If this is causing issues during development, |
| 7725 | * {@code adb shell dpm clear-freeze-period-record} can be used to clear the record. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7726 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7727 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7728 | * components in the device owner package can set system update policies and the most |
| 7729 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7730 | * @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] | 7731 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 29b9a7d | 2018-01-11 09:24:02 +0000 | [diff] [blame] | 7732 | * @throws IllegalArgumentException if the policy type or maintenance window is not valid. |
| 7733 | * @throws SystemUpdatePolicy.ValidationFailedException if the policy's freeze period does not |
| 7734 | * meet the requirement. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 7735 | * @see SystemUpdatePolicy |
Rubin Xu | 29b9a7d | 2018-01-11 09:24:02 +0000 | [diff] [blame] | 7736 | * @see SystemUpdatePolicy#setFreezePeriods(List) |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7737 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7738 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7739 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7740 | if (mService != null) { |
| 7741 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7742 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7743 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7744 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7745 | } |
| 7746 | } |
| 7747 | } |
| 7748 | |
| 7749 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 7750 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7751 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7752 | * @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] | 7753 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7754 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7755 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7756 | if (mService != null) { |
| 7757 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 7758 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7759 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7760 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7761 | } |
| 7762 | } |
| 7763 | return null; |
| 7764 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7765 | |
| 7766 | /** |
Rubin Xu | 29b9a7d | 2018-01-11 09:24:02 +0000 | [diff] [blame] | 7767 | * Reset record of previous system update freeze period the device went through. |
| 7768 | * Only callable by ADB. |
| 7769 | * @hide |
| 7770 | */ |
| 7771 | public void clearSystemUpdatePolicyFreezePeriodRecord() { |
| 7772 | throwIfParentInstance("clearSystemUpdatePolicyFreezePeriodRecord"); |
| 7773 | if (mService == null) { |
| 7774 | return; |
| 7775 | } |
| 7776 | try { |
| 7777 | mService.clearSystemUpdatePolicyFreezePeriodRecord(); |
| 7778 | } catch (RemoteException re) { |
| 7779 | throw re.rethrowFromSystemServer(); |
| 7780 | } |
| 7781 | } |
Pavel Grafov | 5bb5a62 | 2018-01-31 21:06:24 +0000 | [diff] [blame] | 7782 | |
Rubin Xu | 29b9a7d | 2018-01-11 09:24:02 +0000 | [diff] [blame] | 7783 | /** |
Alex Chau | 7fbe61d | 2018-01-04 15:45:38 +0000 | [diff] [blame] | 7784 | * Called by a device owner or profile owner of secondary users that is affiliated with the |
| 7785 | * device to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7786 | * <p> |
| 7787 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 7788 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 7789 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 7790 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7791 | * |
Benjamin Franz | 32a3bf3 | 2017-08-04 15:01:52 +0100 | [diff] [blame] | 7792 | * <p> |
Benjamin Franz | 64affcb | 2017-09-01 13:47:22 +0100 | [diff] [blame] | 7793 | * As of {@link android.os.Build.VERSION_CODES#P}, this call also dismisses the |
Benjamin Franz | 32a3bf3 | 2017-08-04 15:01:52 +0100 | [diff] [blame] | 7794 | * keyguard if it is currently shown. |
| 7795 | * |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7796 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7797 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7798 | * @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] | 7799 | * place. {@code true} otherwise. |
Alex Chau | 7fbe61d | 2018-01-04 15:45:38 +0000 | [diff] [blame] | 7800 | * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of |
| 7801 | * secondary user that is affiliated with the device. |
| 7802 | * @see #isAffiliatedUser |
| 7803 | * @see #getSecondaryUsers |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7804 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7805 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7806 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7807 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7808 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7809 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7810 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7811 | } |
| 7812 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7813 | |
| 7814 | /** |
Alex Chau | 7fbe61d | 2018-01-04 15:45:38 +0000 | [diff] [blame] | 7815 | * Called by device owner or profile owner of secondary users that is affiliated with the |
| 7816 | * device to disable the status bar. Disabling the status bar blocks notifications, quick |
| 7817 | * settings and other screen overlays that allow escaping from a single use device. |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 7818 | * <p> |
| 7819 | * <strong>Note:</strong> This method has no effect for LockTask mode. The behavior of the |
| 7820 | * status bar in LockTask mode can be configured with |
| 7821 | * {@link #setLockTaskFeatures(ComponentName, int)}. Calls to this method when the device is in |
| 7822 | * LockTask mode will be registered, but will only take effect when the device leaves LockTask |
| 7823 | * mode. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7824 | * |
| 7825 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7826 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7827 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
Alex Chau | 7fbe61d | 2018-01-04 15:45:38 +0000 | [diff] [blame] | 7828 | * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of |
| 7829 | * secondary user that is affiliated with the device. |
| 7830 | * @see #isAffiliatedUser |
| 7831 | * @see #getSecondaryUsers |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7832 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7833 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7834 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7835 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7836 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7837 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7838 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7839 | } |
| 7840 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7841 | |
| 7842 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7843 | * Called by the system update service to notify device and profile owners of pending system |
| 7844 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7845 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7846 | * This method should only be used when it is unknown whether the pending system |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7847 | * update is a security patch. Otherwise, use |
| 7848 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 7849 | * |
| 7850 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 7851 | * indicating when the current pending update was first available. {@code -1} if no |
| 7852 | * update is available. |
| 7853 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7854 | * @hide |
| 7855 | */ |
| 7856 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7857 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7858 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7859 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7860 | if (mService != null) { |
| 7861 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7862 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 7863 | } catch (RemoteException re) { |
| 7864 | throw re.rethrowFromSystemServer(); |
| 7865 | } |
| 7866 | } |
| 7867 | } |
| 7868 | |
| 7869 | /** |
| 7870 | * Called by the system update service to notify device and profile owners of pending system |
| 7871 | * updates. |
| 7872 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7873 | * This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7874 | * when it is known whether the pending system update is a security patch. |
| 7875 | * |
| 7876 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 7877 | * indicating when the current pending update was first available. {@code -1} if no |
| 7878 | * update is available. |
| 7879 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 7880 | * {@code false} if not. |
| 7881 | * @see #notifyPendingSystemUpdate(long) |
| 7882 | * @hide |
| 7883 | */ |
| 7884 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7885 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7886 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 7887 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 7888 | if (mService != null) { |
| 7889 | try { |
| 7890 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 7891 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7892 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7893 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7894 | } |
| 7895 | } |
| 7896 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 7897 | |
| 7898 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 7899 | * Called by device or profile owners to get information about a pending system update. |
| 7900 | * |
| 7901 | * @param admin Which profile or device owner this request is associated with. |
| 7902 | * @return Information about a pending system update or {@code null} if no update pending. |
| 7903 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 7904 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 7905 | */ |
| 7906 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 7907 | throwIfParentInstance("getPendingSystemUpdate"); |
| 7908 | try { |
| 7909 | return mService.getPendingSystemUpdate(admin); |
| 7910 | } catch (RemoteException re) { |
| 7911 | throw re.rethrowFromSystemServer(); |
| 7912 | } |
| 7913 | } |
| 7914 | |
| 7915 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7916 | * Set the default response for future runtime permission requests by applications. This |
| 7917 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 7918 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 7919 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 7920 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 7921 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 7922 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 7923 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7924 | * <p/> |
| 7925 | * 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] | 7926 | * 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] | 7927 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7928 | * @param admin Which profile or device owner this request is associated with. |
| 7929 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7930 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 7931 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 7932 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7933 | * @see #setDelegatedScopes |
| 7934 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7935 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7936 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7937 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7938 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7939 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7940 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7941 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7942 | } |
| 7943 | } |
| 7944 | |
| 7945 | /** |
| 7946 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 7947 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7948 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7949 | * @param admin Which profile or device owner this request is associated with. |
| 7950 | * @return the current policy for future permission requests. |
| 7951 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 7952 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7953 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7954 | try { |
| 7955 | return mService.getPermissionPolicy(admin); |
| 7956 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7957 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7958 | } |
| 7959 | } |
| 7960 | |
| 7961 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7962 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 7963 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 7964 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 7965 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 7966 | * the permission is granted and the user cannot manage it through the UI. This method can only |
| 7967 | * be called by a profile owner, device owner, or a delegate given the |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7968 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7969 | * <p/> |
Tony Mak | 329047b | 2018-02-28 14:17:17 +0000 | [diff] [blame] | 7970 | * Note that user cannot manage other permissions in the affected group through the UI |
| 7971 | * either and their granted state will be kept as the current value. Thus, it's recommended that |
| 7972 | * you set the grant state of all the permissions in the affected group. |
| 7973 | * <p/> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7974 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 7975 | * the permission. It retains the previous grant, if any. |
| 7976 | * <p/> |
| 7977 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 7978 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 7979 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7980 | * @param admin Which profile or device owner this request is associated with. |
| 7981 | * @param packageName The application to grant or revoke a permission to. |
| 7982 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7983 | * @param grantState The permission grant state which is one of |
| 7984 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 7985 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 7986 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7987 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 7988 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 7989 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 7990 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7991 | * @see #setDelegatedScopes |
| 7992 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7993 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7994 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 7995 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7996 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7997 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7998 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 7999 | permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 8000 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8001 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 8002 | } |
| 8003 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8004 | |
| 8005 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 8006 | * Returns the current grant state of a runtime permission for a specific application. This |
| 8007 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 8008 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8009 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 8010 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 8011 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8012 | * @param packageName The application to check the grant state for. |
| 8013 | * @param permission The permission to check for. |
| 8014 | * @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] | 8015 | * has not set a grant state, the return value is |
| 8016 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 8017 | * permission is currently granted for the package. |
| 8018 | * <p/> |
| 8019 | * If a grant state was set by the profile or device owner, then the return value will |
| 8020 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 8021 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 8022 | * currently denied or granted. |
| 8023 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8024 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 8025 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 8026 | * @see #setDelegatedScopes |
| 8027 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8028 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 8029 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8030 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8031 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8032 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 8033 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 8034 | permission); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8035 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8036 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 8037 | } |
| 8038 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 8039 | |
| 8040 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8041 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 8042 | * or device, setting itself as the device or profile owner. |
| 8043 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 8044 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 8045 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8046 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 8047 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 8048 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8049 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8050 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 8051 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8052 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 8053 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8054 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 8055 | } |
| 8056 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 8057 | |
| 8058 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8059 | * Checks whether it is possible to initiate provisioning a managed device, |
| 8060 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 8061 | * |
| 8062 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 8063 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 8064 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 8065 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8066 | * @param packageName The package of the component that would be set as device, user, or profile |
| 8067 | * owner. |
| 8068 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 8069 | * @hide |
| 8070 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8071 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 8072 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 8073 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8074 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 8075 | } catch (RemoteException re) { |
| 8076 | throw re.rethrowFromSystemServer(); |
| 8077 | } |
| 8078 | } |
| 8079 | |
| 8080 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 8081 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 8082 | * 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] | 8083 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 8084 | * @param admin Which profile owner this request is associated with. |
| 8085 | * @return if this user is a managed profile of another user. |
| 8086 | */ |
| 8087 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8088 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 8089 | try { |
| 8090 | return mService.isManagedProfile(admin); |
| 8091 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8092 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 8093 | } |
| 8094 | } |
| 8095 | |
| 8096 | /** |
| 8097 | * @hide |
| 8098 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 8099 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 8100 | * @param admin Which device owner this request is associated with. |
| 8101 | * @return if this user is a system-only user. |
| 8102 | */ |
| 8103 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 8104 | try { |
| 8105 | return mService.isSystemOnlyUser(admin); |
| 8106 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8107 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 8108 | } |
| 8109 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 8110 | |
| 8111 | /** |
| 8112 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 8113 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 8114 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8115 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 8116 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 8117 | * <p> |
| 8118 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 8119 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 8120 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8121 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8122 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 8123 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 8124 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 8125 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8126 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 8127 | } |
| 8128 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 8129 | |
| 8130 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 8131 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 8132 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8133 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 8134 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8135 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 8136 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 8137 | */ |
| 8138 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8139 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 8140 | try { |
| 8141 | mService.reboot(admin); |
| 8142 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8143 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 8144 | } |
| 8145 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8146 | |
| 8147 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8148 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 8149 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 8150 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 8151 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 8152 | * truncated. |
| 8153 | * <p> |
| 8154 | * 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] | 8155 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 8156 | * and set a new version of this string accordingly. |
| 8157 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8158 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8159 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8160 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 8161 | * existing message. |
| 8162 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8163 | */ |
| 8164 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8165 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8166 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8167 | if (mService != null) { |
| 8168 | try { |
| 8169 | mService.setShortSupportMessage(admin, message); |
| 8170 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8171 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8172 | } |
| 8173 | } |
| 8174 | } |
| 8175 | |
| 8176 | /** |
| 8177 | * Called by a device admin to get the short support message. |
| 8178 | * |
| 8179 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8180 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 8181 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8182 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8183 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8184 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8185 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8186 | if (mService != null) { |
| 8187 | try { |
| 8188 | return mService.getShortSupportMessage(admin); |
| 8189 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8190 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8191 | } |
| 8192 | } |
| 8193 | return null; |
| 8194 | } |
| 8195 | |
| 8196 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8197 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 8198 | * in the device administators settings screen. |
| 8199 | * <p> |
| 8200 | * 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] | 8201 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 8202 | * and set a new version of this string accordingly. |
| 8203 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8204 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8205 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8206 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 8207 | * existing message. |
| 8208 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8209 | */ |
| 8210 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8211 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8212 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8213 | if (mService != null) { |
| 8214 | try { |
| 8215 | mService.setLongSupportMessage(admin, message); |
| 8216 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8217 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8218 | } |
| 8219 | } |
| 8220 | } |
| 8221 | |
| 8222 | /** |
| 8223 | * Called by a device admin to get the long support message. |
| 8224 | * |
| 8225 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8226 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 8227 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8228 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8229 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8230 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8231 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8232 | if (mService != null) { |
| 8233 | try { |
| 8234 | return mService.getLongSupportMessage(admin); |
| 8235 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8236 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8237 | } |
| 8238 | } |
| 8239 | return null; |
| 8240 | } |
| 8241 | |
| 8242 | /** |
| 8243 | * Called by the system to get the short support message. |
| 8244 | * |
| 8245 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8246 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8247 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8248 | * |
| 8249 | * @hide |
| 8250 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8251 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8252 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8253 | if (mService != null) { |
| 8254 | try { |
| 8255 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 8256 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8257 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8258 | } |
| 8259 | } |
| 8260 | return null; |
| 8261 | } |
| 8262 | |
| 8263 | |
| 8264 | /** |
| 8265 | * Called by the system to get the long support message. |
| 8266 | * |
| 8267 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8268 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 8269 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8270 | * |
| 8271 | * @hide |
| 8272 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8273 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 8274 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8275 | if (mService != null) { |
| 8276 | try { |
| 8277 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 8278 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8279 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 8280 | } |
| 8281 | } |
| 8282 | return null; |
| 8283 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 8284 | |
| 8285 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 8286 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 8287 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 8288 | * |
| 8289 | * <p>The following methods are supported for the parent instance, all other methods will |
| 8290 | * throw a SecurityException when called on the parent instance: |
| 8291 | * <ul> |
| 8292 | * <li>{@link #getPasswordQuality}</li> |
| 8293 | * <li>{@link #setPasswordQuality}</li> |
| 8294 | * <li>{@link #getPasswordMinimumLength}</li> |
| 8295 | * <li>{@link #setPasswordMinimumLength}</li> |
| 8296 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 8297 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 8298 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 8299 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 8300 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 8301 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 8302 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 8303 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 8304 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 8305 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 8306 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 8307 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 8308 | * <li>{@link #getPasswordHistoryLength}</li> |
| 8309 | * <li>{@link #setPasswordHistoryLength}</li> |
| 8310 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 8311 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 8312 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 8313 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 8314 | * <li>{@link #isActivePasswordSufficient}</li> |
| 8315 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 8316 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 8317 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 8318 | * <li>{@link #getMaximumTimeToLock}</li> |
| 8319 | * <li>{@link #setMaximumTimeToLock}</li> |
| 8320 | * <li>{@link #lockNow}</li> |
| 8321 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 8322 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 8323 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 8324 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 8325 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 8326 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 8327 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 8328 | * |
| 8329 | * @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] | 8330 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 8331 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8332 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8333 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 8334 | try { |
| 8335 | if (!mService.isManagedProfile(admin)) { |
| 8336 | throw new SecurityException("The current user does not have a parent profile."); |
| 8337 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 8338 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8339 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8340 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8345 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8346 | * |
| 8347 | * <p> Security logs contain various information intended for security auditing purposes. |
| 8348 | * See {@link SecurityEvent} for details. |
| 8349 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8350 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 8351 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 8352 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 8353 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 8354 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 8355 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8356 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8357 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8358 | * @throws SecurityException if {@code admin} is not a device owner. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8359 | * @see #setAffiliationIds |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8360 | * @see #retrieveSecurityLogs |
| 8361 | */ |
| 8362 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8363 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8364 | try { |
| 8365 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 8366 | } catch (RemoteException re) { |
| 8367 | throw re.rethrowFromSystemServer(); |
| 8368 | } |
| 8369 | } |
| 8370 | |
| 8371 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8372 | * Return whether security logging is enabled or not by the device owner. |
| 8373 | * |
| 8374 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 8375 | * thrown. |
| 8376 | * |
| 8377 | * @param admin Which device owner this request is associated with. |
| 8378 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 8379 | * @throws SecurityException if {@code admin} is not a device owner. |
| 8380 | */ |
Bartosz Fabianowski | 0ec0000 | 2017-03-24 14:22:24 +0100 | [diff] [blame] | 8381 | public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8382 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8383 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8384 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8385 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8386 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8387 | } |
| 8388 | } |
| 8389 | |
| 8390 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8391 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 8392 | * this API after device boots. |
| 8393 | * |
| 8394 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 8395 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 8396 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8397 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8398 | * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 8399 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8400 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8401 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 8402 | * 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] | 8403 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8404 | * profile or secondary user that is not affiliated with the device. |
| 8405 | * @see #isAffiliatedUser |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8406 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8407 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8408 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8409 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8410 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8411 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8412 | if (list != null) { |
| 8413 | return list.getList(); |
| 8414 | } else { |
| 8415 | // Rate limit exceeded. |
| 8416 | return null; |
| 8417 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 8418 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8419 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 8420 | } |
| 8421 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8422 | |
| 8423 | /** |
Pavel Grafov | 5bb5a62 | 2018-01-31 21:06:24 +0000 | [diff] [blame] | 8424 | * Forces a batch of security logs to be fetched from logd and makes it available for DPC. |
| 8425 | * Only callable by ADB. If throttled, returns time to wait in milliseconds, otherwise 0. |
| 8426 | * @hide |
| 8427 | */ |
| 8428 | public long forceSecurityLogs() { |
| 8429 | if (mService == null) { |
| 8430 | return 0; |
| 8431 | } |
| 8432 | try { |
| 8433 | return mService.forceSecurityLogs(); |
| 8434 | } catch (RemoteException re) { |
| 8435 | throw re.rethrowFromSystemServer(); |
| 8436 | } |
| 8437 | } |
| 8438 | |
| 8439 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 8440 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 8441 | * profile. |
| 8442 | * |
| 8443 | * @hide |
| 8444 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8445 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 8446 | mContext.checkSelfPermission( |
| 8447 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 8448 | if (!uInfo.isManagedProfile()) { |
| 8449 | throw new SecurityException("The user " + uInfo.id |
| 8450 | + " does not have a parent profile."); |
| 8451 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 8452 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 8453 | } |
| 8454 | |
| 8455 | /** |
Sudheer Shanka | 5be44ff | 2018-01-23 15:15:03 -0800 | [diff] [blame] | 8456 | * Called by a device or profile owner to restrict packages from using metered data. |
Sudheer Shanka | 04d61ae | 2018-01-17 12:16:57 -0800 | [diff] [blame] | 8457 | * |
| 8458 | * @param admin which {@link DeviceAdminReceiver} this request is associated with. |
| 8459 | * @param packageNames the list of package names to be restricted. |
| 8460 | * @return a list of package names which could not be restricted. |
| 8461 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 8462 | */ |
Michael Wachenschwanz | 5416468 | 2018-03-08 16:23:52 -0800 | [diff] [blame] | 8463 | public @NonNull List<String> setMeteredDataDisabledPackages(@NonNull ComponentName admin, |
Sudheer Shanka | 04d61ae | 2018-01-17 12:16:57 -0800 | [diff] [blame] | 8464 | @NonNull List<String> packageNames) { |
| 8465 | throwIfParentInstance("setMeteredDataDisabled"); |
| 8466 | if (mService != null) { |
| 8467 | try { |
Michael Wachenschwanz | 5416468 | 2018-03-08 16:23:52 -0800 | [diff] [blame] | 8468 | return mService.setMeteredDataDisabledPackages(admin, packageNames); |
Sudheer Shanka | 04d61ae | 2018-01-17 12:16:57 -0800 | [diff] [blame] | 8469 | } catch (RemoteException re) { |
| 8470 | throw re.rethrowFromSystemServer(); |
| 8471 | } |
| 8472 | } |
| 8473 | return packageNames; |
| 8474 | } |
| 8475 | |
| 8476 | /** |
| 8477 | * Called by a device or profile owner to retrieve the list of packages which are restricted |
Sudheer Shanka | 5be44ff | 2018-01-23 15:15:03 -0800 | [diff] [blame] | 8478 | * by the admin from using metered data. |
Sudheer Shanka | 04d61ae | 2018-01-17 12:16:57 -0800 | [diff] [blame] | 8479 | * |
| 8480 | * @param admin which {@link DeviceAdminReceiver} this request is associated with. |
| 8481 | * @return the list of restricted package names. |
| 8482 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 8483 | */ |
Michael Wachenschwanz | 5416468 | 2018-03-08 16:23:52 -0800 | [diff] [blame] | 8484 | public @NonNull List<String> getMeteredDataDisabledPackages(@NonNull ComponentName admin) { |
Sudheer Shanka | 04d61ae | 2018-01-17 12:16:57 -0800 | [diff] [blame] | 8485 | throwIfParentInstance("getMeteredDataDisabled"); |
| 8486 | if (mService != null) { |
| 8487 | try { |
Michael Wachenschwanz | 5416468 | 2018-03-08 16:23:52 -0800 | [diff] [blame] | 8488 | return mService.getMeteredDataDisabledPackages(admin); |
Sudheer Shanka | 04d61ae | 2018-01-17 12:16:57 -0800 | [diff] [blame] | 8489 | } catch (RemoteException re) { |
| 8490 | throw re.rethrowFromSystemServer(); |
| 8491 | } |
| 8492 | } |
| 8493 | return new ArrayList<>(); |
| 8494 | } |
| 8495 | |
| 8496 | /** |
Sudheer Shanka | 5be44ff | 2018-01-23 15:15:03 -0800 | [diff] [blame] | 8497 | * Called by the system to check if a package is restricted from using metered data |
| 8498 | * by {@param admin}. |
| 8499 | * |
| 8500 | * @param admin which {@link DeviceAdminReceiver} this request is associated with. |
| 8501 | * @param packageName the package whose restricted status is needed. |
| 8502 | * @param userId the user to which {@param packageName} belongs. |
| 8503 | * @return {@code true} if the package is restricted by admin, otherwise {@code false} |
| 8504 | * @throws SecurityException if the caller doesn't run with {@link Process#SYSTEM_UID} |
| 8505 | * @hide |
| 8506 | */ |
Michael Wachenschwanz | 5416468 | 2018-03-08 16:23:52 -0800 | [diff] [blame] | 8507 | public boolean isMeteredDataDisabledPackageForUser(@NonNull ComponentName admin, |
| 8508 | String packageName, @UserIdInt int userId) { |
Sudheer Shanka | 5be44ff | 2018-01-23 15:15:03 -0800 | [diff] [blame] | 8509 | throwIfParentInstance("getMeteredDataDisabledForUser"); |
| 8510 | if (mService != null) { |
| 8511 | try { |
Michael Wachenschwanz | 5416468 | 2018-03-08 16:23:52 -0800 | [diff] [blame] | 8512 | return mService.isMeteredDataDisabledPackageForUser(admin, packageName, userId); |
Sudheer Shanka | 5be44ff | 2018-01-23 15:15:03 -0800 | [diff] [blame] | 8513 | } catch (RemoteException re) { |
| 8514 | throw re.rethrowFromSystemServer(); |
| 8515 | } |
| 8516 | } |
| 8517 | return false; |
| 8518 | } |
| 8519 | |
| 8520 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8521 | * 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] | 8522 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 8523 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 8524 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 8525 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 8526 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8527 | * |
| 8528 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8529 | * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 8530 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8531 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 8532 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 8533 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8534 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8535 | * profile or secondary user that is not affiliated with the device. |
| 8536 | * @see #isAffiliatedUser |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8537 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8538 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8539 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 8540 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8541 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8542 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 8543 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 8544 | if (list != null) { |
| 8545 | return list.getList(); |
| 8546 | } else { |
| 8547 | return null; |
| 8548 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8549 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8550 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 8551 | } |
| 8552 | } |
| 8553 | |
| 8554 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8555 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 8556 | * 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] | 8557 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8558 | * <p> |
| 8559 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8560 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 8561 | * |
| 8562 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8563 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8564 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8565 | */ |
| 8566 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8567 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8568 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8569 | // always enforce alpha channel to have 100% opacity |
| 8570 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8571 | mService.setOrganizationColor(admin, color); |
| 8572 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8573 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8574 | } |
| 8575 | } |
| 8576 | |
| 8577 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 8578 | * @hide |
| 8579 | * |
| 8580 | * Sets the color used for customization. |
| 8581 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8582 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 8583 | * @param userId which user to set the color to. |
| 8584 | * @RequiresPermission(allOf = { |
| 8585 | * Manifest.permission.MANAGE_USERS, |
| 8586 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 8587 | */ |
| 8588 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 8589 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8590 | // always enforce alpha channel to have 100% opacity |
| 8591 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 8592 | mService.setOrganizationColorForUser(color, userId); |
| 8593 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8594 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 8595 | } |
| 8596 | } |
| 8597 | |
| 8598 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8599 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 8600 | * This color is used as background color of the confirm credentials screen for that user. |
| 8601 | * |
| 8602 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8603 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8604 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8605 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8606 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8607 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8608 | try { |
| 8609 | return mService.getOrganizationColor(admin); |
| 8610 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8611 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8612 | } |
| 8613 | } |
| 8614 | |
| 8615 | /** |
| 8616 | * @hide |
| 8617 | * Retrieve the customization color for a given user. |
| 8618 | * |
| 8619 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8620 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8621 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8622 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8623 | try { |
| 8624 | return mService.getOrganizationColorForUser(userHandle); |
| 8625 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8626 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 8627 | } |
| 8628 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8629 | |
| 8630 | /** |
Wen ZHANG | 2be4cfc | 2017-09-21 18:29:43 +0100 | [diff] [blame] | 8631 | * Called by the device owner (since API 26) or profile owner (since API 24) to set the name of |
| 8632 | * the organization under management. |
| 8633 | * |
| 8634 | * <p>If the organization name needs to be localized, it is the responsibility of the {@link |
| 8635 | * DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast and set |
| 8636 | * a new version of this string accordingly. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8637 | * |
| 8638 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8639 | * @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] | 8640 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8641 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 8642 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8643 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8644 | try { |
| 8645 | mService.setOrganizationName(admin, title); |
| 8646 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8647 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8648 | } |
| 8649 | } |
| 8650 | |
| 8651 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8652 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 8653 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8654 | * |
| 8655 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8656 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 8657 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8658 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8659 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8660 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8661 | try { |
| 8662 | return mService.getOrganizationName(admin); |
| 8663 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8664 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8665 | } |
| 8666 | } |
| 8667 | |
| 8668 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 8669 | * Called by the system to retrieve the name of the organization managing the device. |
| 8670 | * |
| 8671 | * @return The organization name or {@code null} if none is set. |
| 8672 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8673 | * MANAGE_USERS permission and is not the system. |
| 8674 | * |
| 8675 | * @hide |
| 8676 | */ |
| 8677 | @SystemApi |
| 8678 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 8679 | @SuppressLint("Doclava125") |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 8680 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 8681 | try { |
| 8682 | return mService.getDeviceOwnerOrganizationName(); |
| 8683 | } catch (RemoteException re) { |
| 8684 | throw re.rethrowFromSystemServer(); |
| 8685 | } |
| 8686 | } |
| 8687 | |
| 8688 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8689 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 8690 | * |
| 8691 | * @param userHandle The user id of the user we're interested in. |
| 8692 | * @return The organization name or {@code null} if none is set. |
| 8693 | * |
| 8694 | * @hide |
| 8695 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 8696 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8697 | try { |
| 8698 | return mService.getOrganizationNameForUser(userHandle); |
| 8699 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8700 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 8701 | } |
| 8702 | } |
| 8703 | |
| 8704 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 8705 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 8706 | * return {@link #STATE_USER_UNMANAGED} |
| 8707 | * @hide |
| 8708 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 8709 | @SystemApi |
Eric Sandness | 3780c09 | 2018-03-23 16:16:11 +0000 | [diff] [blame] | 8710 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 8711 | @UserProvisioningState |
| 8712 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8713 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 8714 | if (mService != null) { |
| 8715 | try { |
| 8716 | return mService.getUserProvisioningState(); |
| 8717 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8718 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 8719 | } |
| 8720 | } |
| 8721 | return STATE_USER_UNMANAGED; |
| 8722 | } |
| 8723 | |
| 8724 | /** |
| 8725 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 8726 | * |
| 8727 | * @param state to store |
| 8728 | * @param userHandle for user |
| 8729 | * @hide |
| 8730 | */ |
| 8731 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 8732 | if (mService != null) { |
| 8733 | try { |
| 8734 | mService.setUserProvisioningState(state, userHandle); |
| 8735 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8736 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 8737 | } |
| 8738 | } |
| 8739 | } |
| 8740 | |
| 8741 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 8742 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 8743 | * 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] | 8744 | * |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8745 | * <p>A user/profile that is affiliated with the device owner user is considered to be |
| 8746 | * affiliated with the device. |
| 8747 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8748 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 8749 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 8750 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 8751 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 8752 | * created. |
| 8753 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8754 | * @param admin Which profile or device owner this request is associated with. |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 8755 | * @param ids A set of opaque non-empty affiliation ids. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 8756 | * |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 8757 | * @throws IllegalArgumentException if {@code ids} is null or contains an empty string. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8758 | * @see #isAffiliatedUser |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 8759 | */ |
| 8760 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) { |
| 8761 | throwIfParentInstance("setAffiliationIds"); |
| 8762 | if (ids == null) { |
| 8763 | throw new IllegalArgumentException("ids must not be null"); |
| 8764 | } |
| 8765 | try { |
| 8766 | mService.setAffiliationIds(admin, new ArrayList<>(ids)); |
| 8767 | } catch (RemoteException e) { |
| 8768 | throw e.rethrowFromSystemServer(); |
| 8769 | } |
| 8770 | } |
| 8771 | |
| 8772 | /** |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 8773 | * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 8774 | * empty set if none have been set. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 8775 | */ |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 8776 | public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) { |
Tony Mak | 62cf586 | 2017-05-02 13:50:18 +0100 | [diff] [blame] | 8777 | throwIfParentInstance("getAffiliationIds"); |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 8778 | try { |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 8779 | return new ArraySet<>(mService.getAffiliationIds(admin)); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8780 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8781 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8782 | } |
| 8783 | } |
| 8784 | |
| 8785 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 8786 | * Returns whether this user/profile is affiliated with the device. |
| 8787 | * <p> |
| 8788 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 8789 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 8790 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 8791 | * @see #setAffiliationIds |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8792 | */ |
| 8793 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8794 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8795 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 8796 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8797 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8798 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 8799 | } |
| 8800 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 8801 | |
| 8802 | /** |
| 8803 | * @hide |
| 8804 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 8805 | * to be started |
| 8806 | * @param packageName the package to check for |
| 8807 | * @return whether the uninstall intent for {@code packageName} is pending |
| 8808 | */ |
| 8809 | public boolean isUninstallInQueue(String packageName) { |
| 8810 | try { |
| 8811 | return mService.isUninstallInQueue(packageName); |
| 8812 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8813 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 8814 | } |
| 8815 | } |
| 8816 | |
| 8817 | /** |
| 8818 | * @hide |
| 8819 | * @param packageName the package containing active DAs to be uninstalled |
| 8820 | */ |
| 8821 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 8822 | try { |
| 8823 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 8824 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 8825 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 8826 | } |
| 8827 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8828 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 8829 | /** |
| 8830 | * @hide |
| 8831 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 8832 | * If the admin is a profile owner or device owner it will still be removed. |
| 8833 | * |
| 8834 | * @param userHandle user id to remove the admin for. |
| 8835 | * @param admin The administration compononent to remove. |
| 8836 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 8837 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 8838 | */ |
| 8839 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 8840 | try { |
| 8841 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 8842 | } catch (RemoteException re) { |
| 8843 | throw re.rethrowFromSystemServer(); |
| 8844 | } |
| 8845 | } |
| 8846 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 8847 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8848 | * Returns whether the device has been provisioned. |
| 8849 | * |
| 8850 | * <p>Not for use by third-party applications. |
| 8851 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 8852 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 8853 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8854 | @SystemApi |
Eric Sandness | df30c7d | 2018-03-27 09:56:40 +0100 | [diff] [blame] | 8855 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 8856 | public boolean isDeviceProvisioned() { |
| 8857 | try { |
| 8858 | return mService.isDeviceProvisioned(); |
| 8859 | } catch (RemoteException re) { |
| 8860 | throw re.rethrowFromSystemServer(); |
| 8861 | } |
| 8862 | } |
| 8863 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8864 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8865 | * Writes that the provisioning configuration has been applied. |
| 8866 | * |
| 8867 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 8868 | * permission. |
| 8869 | * |
| 8870 | * <p>Not for use by third-party applications. |
| 8871 | * |
| 8872 | * @hide |
| 8873 | */ |
| 8874 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 8875 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8876 | public void setDeviceProvisioningConfigApplied() { |
| 8877 | try { |
| 8878 | mService.setDeviceProvisioningConfigApplied(); |
| 8879 | } catch (RemoteException re) { |
| 8880 | throw re.rethrowFromSystemServer(); |
| 8881 | } |
| 8882 | } |
| 8883 | |
| 8884 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8885 | * Returns whether the provisioning configuration has been applied. |
| 8886 | * |
| 8887 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 8888 | * |
| 8889 | * <p>Not for use by third-party applications. |
| 8890 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8891 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8892 | * |
| 8893 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8894 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8895 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 8896 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8897 | public boolean isDeviceProvisioningConfigApplied() { |
| 8898 | try { |
| 8899 | return mService.isDeviceProvisioningConfigApplied(); |
| 8900 | } catch (RemoteException re) { |
| 8901 | throw re.rethrowFromSystemServer(); |
| 8902 | } |
| 8903 | } |
| 8904 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 8905 | /** |
| 8906 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 8907 | * Force update user setup completed status. This API has no effect on user build. |
| 8908 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8909 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 8910 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 8911 | */ |
| 8912 | public void forceUpdateUserSetupComplete() { |
| 8913 | try { |
| 8914 | mService.forceUpdateUserSetupComplete(); |
| 8915 | } catch (RemoteException re) { |
| 8916 | throw re.rethrowFromSystemServer(); |
| 8917 | } |
| 8918 | } |
| 8919 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 8920 | @UnsupportedAppUsage |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8921 | private void throwIfParentInstance(String functionName) { |
| 8922 | if (mParentInstance) { |
| 8923 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 8924 | } |
| 8925 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8926 | |
| 8927 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8928 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8929 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8930 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 8931 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8932 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8933 | * <p> Backup service is off by default when device owner is present. |
| 8934 | * |
Rubin Xu | 0367f07 | 2017-04-24 20:17:16 +0100 | [diff] [blame] | 8935 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8936 | * @param enabled {@code true} to enable the backup service, {@code false} to disable it. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8937 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8938 | */ |
| 8939 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 8940 | throwIfParentInstance("setBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8941 | try { |
| 8942 | mService.setBackupServiceEnabled(admin, enabled); |
| 8943 | } catch (RemoteException re) { |
| 8944 | throw re.rethrowFromSystemServer(); |
| 8945 | } |
| 8946 | } |
| 8947 | |
| 8948 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8949 | * Return whether the backup service is enabled by the device owner. |
| 8950 | * |
| 8951 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 8952 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8953 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8954 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8955 | */ |
| 8956 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 8957 | throwIfParentInstance("isBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8958 | try { |
| 8959 | return mService.isBackupServiceEnabled(admin); |
| 8960 | } catch (RemoteException re) { |
| 8961 | throw re.rethrowFromSystemServer(); |
| 8962 | } |
| 8963 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8964 | |
| 8965 | /** |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 8966 | * Makes backups mandatory and enforces the usage of the specified backup transport. |
| 8967 | * |
| 8968 | * <p>When a {@code null} backup transport is specified, backups are made optional again. |
| 8969 | * <p>Only device owner can call this method. |
| 8970 | * <p>If backups were disabled and a non-null backup transport {@link ComponentName} is |
| 8971 | * specified, backups will be enabled. |
Lenka Trochtova | 27fd821 | 2018-04-10 11:01:58 +0200 | [diff] [blame] | 8972 | * <p> If the backup service is disabled after the mandatory backup transport has been set, the |
| 8973 | * mandatory backup transport is cleared. |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 8974 | * |
Lenka Trochtova | 56681f7 | 2018-03-09 15:47:50 +0100 | [diff] [blame] | 8975 | * <p>NOTE: The method shouldn't be called on the main thread. |
| 8976 | * |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 8977 | * @param admin admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8978 | * @param backupTransportComponent The backup transport layer to be used for mandatory backups. |
Lenka Trochtova | 56681f7 | 2018-03-09 15:47:50 +0100 | [diff] [blame] | 8979 | * @return {@code true} if the backup transport was successfully set; {@code false} otherwise. |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 8980 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | 27fd821 | 2018-04-10 11:01:58 +0200 | [diff] [blame] | 8981 | * @hide |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 8982 | */ |
Lenka Trochtova | 56681f7 | 2018-03-09 15:47:50 +0100 | [diff] [blame] | 8983 | @WorkerThread |
| 8984 | public boolean setMandatoryBackupTransport( |
| 8985 | @NonNull ComponentName admin, |
| 8986 | @Nullable ComponentName backupTransportComponent) { |
Lenka Trochtova | 6290012 | 2018-01-23 14:55:46 +0100 | [diff] [blame] | 8987 | throwIfParentInstance("setMandatoryBackupTransport"); |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 8988 | try { |
Lenka Trochtova | 56681f7 | 2018-03-09 15:47:50 +0100 | [diff] [blame] | 8989 | return mService.setMandatoryBackupTransport(admin, backupTransportComponent); |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 8990 | } catch (RemoteException re) { |
| 8991 | throw re.rethrowFromSystemServer(); |
| 8992 | } |
| 8993 | } |
| 8994 | |
| 8995 | /** |
| 8996 | * Returns the backup transport which has to be used for backups if backups are mandatory or |
| 8997 | * {@code null} if backups are not mandatory. |
| 8998 | * |
| 8999 | * @return a {@link ComponentName} of the backup transport layer to be used if backups are |
| 9000 | * mandatory or {@code null} if backups are not mandatory. |
Lenka Trochtova | 27fd821 | 2018-04-10 11:01:58 +0200 | [diff] [blame] | 9001 | * @hide |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 9002 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 9003 | @UnsupportedAppUsage |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 9004 | public ComponentName getMandatoryBackupTransport() { |
Lenka Trochtova | 6290012 | 2018-01-23 14:55:46 +0100 | [diff] [blame] | 9005 | throwIfParentInstance("getMandatoryBackupTransport"); |
Lenka Trochtova | c141d08 | 2017-12-20 14:45:16 +0100 | [diff] [blame] | 9006 | try { |
| 9007 | return mService.getMandatoryBackupTransport(); |
| 9008 | } catch (RemoteException re) { |
| 9009 | throw re.rethrowFromSystemServer(); |
| 9010 | } |
| 9011 | } |
| 9012 | |
| 9013 | |
| 9014 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 9015 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 9016 | * |
Robin Lee | a40a2fb | 2017-02-08 17:07:06 +0000 | [diff] [blame] | 9017 | * <p> Network logs contain DNS lookup and connect() library call events. The following library |
| 9018 | * functions are recorded while network logging is active: |
| 9019 | * <ul> |
| 9020 | * <li>{@code getaddrinfo()}</li> |
| 9021 | * <li>{@code gethostbyname()}</li> |
| 9022 | * <li>{@code connect()}</li> |
| 9023 | * </ul> |
| 9024 | * |
| 9025 | * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use |
| 9026 | * full system call logging; event reporting is enabled by default for all processes but not |
| 9027 | * strongly enforced. |
| 9028 | * Events from applications using alternative implementations of libc, making direct kernel |
| 9029 | * calls, or deliberately obfuscating traffic may not be recorded. |
| 9030 | * |
| 9031 | * <p> Some common network events may not be reported. For example: |
| 9032 | * <ul> |
| 9033 | * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use |
| 9034 | * an alternative system for name resolution, and so avoid calling |
| 9035 | * {@code getaddrinfo()} or {@code gethostbyname}.</li> |
| 9036 | * <li>Applications may use datagram sockets for performance reasons, for example |
| 9037 | * for a game client. Calling {@code connect()} is unnecessary for this kind of |
| 9038 | * socket, so it will not trigger a network event.</li> |
| 9039 | * </ul> |
| 9040 | * |
| 9041 | * <p> It is possible to directly intercept layer 3 traffic leaving the device using an |
| 9042 | * always-on VPN service. |
| 9043 | * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} |
| 9044 | * and {@link android.net.VpnService} for details. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 9045 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 9046 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 9047 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 9048 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 9049 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 9050 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 9051 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 9052 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 9053 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 9054 | * @throws SecurityException if {@code admin} is not a device owner. |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 9055 | * @see #setAffiliationIds |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 9056 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 9057 | */ |
| 9058 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 9059 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 9060 | try { |
| 9061 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 9062 | } catch (RemoteException re) { |
| 9063 | throw re.rethrowFromSystemServer(); |
| 9064 | } |
| 9065 | } |
| 9066 | |
| 9067 | /** |
| 9068 | * Return whether network logging is enabled by a device owner. |
| 9069 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 9070 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 9071 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 9072 | * @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] | 9073 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 9074 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 9075 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 9076 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 9077 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 9078 | try { |
| 9079 | return mService.isNetworkLoggingEnabled(admin); |
| 9080 | } catch (RemoteException re) { |
| 9081 | throw re.rethrowFromSystemServer(); |
| 9082 | } |
| 9083 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 9084 | |
| 9085 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 9086 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 9087 | * A device owner has to provide a batchToken provided as part of |
| 9088 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 9089 | * 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] | 9090 | * |
| 9091 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 9092 | * |
| 9093 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 9094 | * |
| 9095 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 9096 | * after the device device owner has been notified via |
| 9097 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 9098 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 9099 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 9100 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 9101 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 9102 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 9103 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 9104 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 9105 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 9106 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 9107 | * @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] | 9108 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 9109 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 9110 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
Alex Chau | 443b643 | 2017-12-13 12:44:31 +0000 | [diff] [blame] | 9111 | * profile or secondary user that is not affiliated with the device. |
| 9112 | * @see #setAffiliationIds |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 9113 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 9114 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 9115 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 9116 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 9117 | throwIfParentInstance("retrieveNetworkLogs"); |
| 9118 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 9119 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 9120 | } catch (RemoteException re) { |
| 9121 | throw re.rethrowFromSystemServer(); |
| 9122 | } |
| 9123 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 9124 | |
| 9125 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 9126 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 9127 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9128 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 9129 | * <p> |
Tony Mak | eda0a9a | 2017-04-25 12:07:14 +0100 | [diff] [blame] | 9130 | * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
| 9131 | * Note that the {@link Context} used to obtain this |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 9132 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 9133 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9134 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 9135 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 9136 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 9137 | * explicit component name or a package name to match an |
| 9138 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 9139 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 9140 | * 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] | 9141 | * @param flags Operation options for the binding operation. See |
| 9142 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9143 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 9144 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 9145 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 9146 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 9147 | * {@code false} is returned if the connection is not made and you will not |
| 9148 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9149 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 9150 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9151 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 9152 | */ |
| 9153 | public boolean bindDeviceAdminServiceAsUser( |
| 9154 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 9155 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 9156 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 9157 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 9158 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 9159 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 9160 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 9161 | serviceIntent.prepareToLeaveProcess(mContext); |
| 9162 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 9163 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 9164 | sd, flags, targetUser.getIdentifier()); |
| 9165 | } catch (RemoteException re) { |
| 9166 | throw re.rethrowFromSystemServer(); |
| 9167 | } |
| 9168 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9169 | |
| 9170 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9171 | * Returns the list of target users that the calling device or profile owner can use when |
| 9172 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 9173 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 9174 | * A device owner can bind to a service from a profile owner and vice versa, provided that: |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9175 | * <ul> |
| 9176 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 9177 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 9178 | * </ul> |
| 9179 | */ |
| 9180 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 9181 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 9182 | try { |
| 9183 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 9184 | } catch (RemoteException re) { |
| 9185 | throw re.rethrowFromSystemServer(); |
| 9186 | } |
| 9187 | } |
| 9188 | |
| 9189 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9190 | * Called by the system to get the time at which the device owner last retrieved security |
| 9191 | * logging entries. |
| 9192 | * |
| 9193 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 9194 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 9195 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 9196 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9197 | * |
| 9198 | * @hide |
| 9199 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 9200 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9201 | public long getLastSecurityLogRetrievalTime() { |
| 9202 | try { |
| 9203 | return mService.getLastSecurityLogRetrievalTime(); |
| 9204 | } catch (RemoteException re) { |
| 9205 | throw re.rethrowFromSystemServer(); |
| 9206 | } |
| 9207 | } |
| 9208 | |
| 9209 | /** |
| 9210 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 9211 | * |
| 9212 | * @return the time at which the device owner most recently requested a bug report, in |
| 9213 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 9214 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 9215 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9216 | * |
| 9217 | * @hide |
| 9218 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 9219 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9220 | public long getLastBugReportRequestTime() { |
| 9221 | try { |
| 9222 | return mService.getLastBugReportRequestTime(); |
| 9223 | } catch (RemoteException re) { |
| 9224 | throw re.rethrowFromSystemServer(); |
| 9225 | } |
| 9226 | } |
| 9227 | |
| 9228 | /** |
| 9229 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 9230 | * events. |
| 9231 | * |
| 9232 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 9233 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 9234 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 9235 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9236 | * |
| 9237 | * @hide |
| 9238 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 9239 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 9240 | public long getLastNetworkLogRetrievalTime() { |
| 9241 | try { |
| 9242 | return mService.getLastNetworkLogRetrievalTime(); |
| 9243 | } catch (RemoteException re) { |
| 9244 | throw re.rethrowFromSystemServer(); |
| 9245 | } |
| 9246 | } |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 9247 | |
| 9248 | /** |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 9249 | * Called by the system to find out whether the current user's IME was set by the device/profile |
| 9250 | * owner or the user. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 9251 | * |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 9252 | * @return {@code true} if the user's IME was set by the device or profile owner, {@code false} |
| 9253 | * otherwise. |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 9254 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 9255 | * |
| 9256 | * @hide |
| 9257 | */ |
| 9258 | @TestApi |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 9259 | public boolean isCurrentInputMethodSetByOwner() { |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 9260 | try { |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 9261 | return mService.isCurrentInputMethodSetByOwner(); |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 9262 | } catch (RemoteException re) { |
| 9263 | throw re.rethrowFromSystemServer(); |
| 9264 | } |
| 9265 | } |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 9266 | |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 9267 | /** |
| 9268 | * Called by the system to get a list of CA certificates that were installed by the device or |
| 9269 | * profile owner. |
| 9270 | * |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 9271 | * <p> The caller must be the target user's device owner/profile Owner or hold the |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 9272 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 9273 | * |
| 9274 | * @param user The user for whom to retrieve information. |
| 9275 | * @return list of aliases identifying CA certificates installed by the device or profile owner |
| 9276 | * @throws SecurityException if the caller does not have permission to retrieve information |
| 9277 | * about the given user's CA certificates. |
| 9278 | * |
| 9279 | * @hide |
| 9280 | */ |
| 9281 | @TestApi |
| 9282 | public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) { |
| 9283 | try { |
| 9284 | return mService.getOwnerInstalledCaCerts(user).getList(); |
| 9285 | } catch (RemoteException re) { |
| 9286 | throw re.rethrowFromSystemServer(); |
| 9287 | } |
| 9288 | } |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9289 | |
| 9290 | /** |
| 9291 | * Called by the device owner or profile owner to clear application user data of a given |
| 9292 | * package. The behaviour of this is equivalent to the target application calling |
| 9293 | * {@link android.app.ActivityManager#clearApplicationUserData()}. |
| 9294 | * |
| 9295 | * <p><strong>Note:</strong> an application can store data outside of its application data, e.g. |
| 9296 | * external storage or user dictionary. This data will not be wiped by calling this API. |
| 9297 | * |
| 9298 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 9299 | * @param packageName The name of the package which will have its user data wiped. |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 9300 | * @param executor The executor through which the listener should be invoked. |
Alex Chau | 4a4285b | 2018-01-12 13:35:06 +0000 | [diff] [blame] | 9301 | * @param listener A callback object that will inform the caller when the clearing is done. |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9302 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9303 | */ |
Alex Chau | 1033e38 | 2018-01-25 15:53:39 +0000 | [diff] [blame] | 9304 | public void clearApplicationUserData(@NonNull ComponentName admin, |
Alex Chau | 4a4285b | 2018-01-12 13:35:06 +0000 | [diff] [blame] | 9305 | @NonNull String packageName, @NonNull @CallbackExecutor Executor executor, |
| 9306 | @NonNull OnClearApplicationUserDataListener listener) { |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9307 | throwIfParentInstance("clearAppData"); |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 9308 | Preconditions.checkNotNull(executor); |
Alex Chau | 1033e38 | 2018-01-25 15:53:39 +0000 | [diff] [blame] | 9309 | Preconditions.checkNotNull(listener); |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9310 | try { |
Alex Chau | 1033e38 | 2018-01-25 15:53:39 +0000 | [diff] [blame] | 9311 | mService.clearApplicationUserData(admin, packageName, |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9312 | new IPackageDataObserver.Stub() { |
| 9313 | public void onRemoveCompleted(String pkg, boolean succeeded) { |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 9314 | executor.execute(() -> |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9315 | listener.onApplicationUserDataCleared(pkg, succeeded)); |
| 9316 | } |
| 9317 | }); |
| 9318 | } catch (RemoteException re) { |
| 9319 | throw re.rethrowFromSystemServer(); |
| 9320 | } |
| 9321 | } |
| 9322 | |
| 9323 | /** |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9324 | * Called by a device owner to specify whether logout is enabled for all secondary users. The |
| 9325 | * system may show a logout button that stops the user and switches back to the primary user. |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9326 | * |
| 9327 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9328 | * @param enabled whether logout should be enabled or not. |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9329 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9330 | */ |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9331 | public void setLogoutEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 9332 | throwIfParentInstance("setLogoutEnabled"); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9333 | try { |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9334 | mService.setLogoutEnabled(admin, enabled); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9335 | } catch (RemoteException re) { |
| 9336 | throw re.rethrowFromSystemServer(); |
| 9337 | } |
| 9338 | } |
| 9339 | |
| 9340 | /** |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9341 | * Returns whether logout is enabled by a device owner. |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9342 | * |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9343 | * @return {@code true} if logout is enabled by device owner, {@code false} otherwise. |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9344 | */ |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9345 | public boolean isLogoutEnabled() { |
| 9346 | throwIfParentInstance("isLogoutEnabled"); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9347 | try { |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 9348 | return mService.isLogoutEnabled(); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 9349 | } catch (RemoteException re) { |
| 9350 | throw re.rethrowFromSystemServer(); |
| 9351 | } |
| 9352 | } |
| 9353 | |
| 9354 | /** |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 9355 | * Callback used in {@link #clearApplicationUserData} |
| 9356 | * to indicate that the clearing of an application's user data is done. |
| 9357 | */ |
| 9358 | public interface OnClearApplicationUserDataListener { |
| 9359 | /** |
| 9360 | * Method invoked when clearing the application user data has completed. |
| 9361 | * |
| 9362 | * @param packageName The name of the package which had its user data cleared. |
| 9363 | * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator |
| 9364 | * apps and protected system packages. |
| 9365 | */ |
| 9366 | void onApplicationUserDataCleared(String packageName, boolean succeeded); |
| 9367 | } |
Alex Chau | b6a9f94 | 2017-11-07 11:28:56 +0800 | [diff] [blame] | 9368 | |
| 9369 | /** |
| 9370 | * Returns set of system apps that should be removed during provisioning. |
| 9371 | * |
| 9372 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 9373 | * @param userId ID of the user to be provisioned. |
| 9374 | * @param provisioningAction action indicating type of provisioning, should be one of |
| 9375 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}, {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 9376 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
| 9377 | * |
| 9378 | * @hide |
| 9379 | */ |
| 9380 | public Set<String> getDisallowedSystemApps(ComponentName admin, int userId, |
| 9381 | String provisioningAction) { |
| 9382 | try { |
| 9383 | return new ArraySet<>( |
| 9384 | mService.getDisallowedSystemApps(admin, userId, provisioningAction)); |
| 9385 | } catch (RemoteException re) { |
| 9386 | throw re.rethrowFromSystemServer(); |
| 9387 | } |
| 9388 | } |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9389 | |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9390 | /** |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9391 | * Changes the current administrator to another one. All policies from the current |
| 9392 | * administrator are migrated to the new administrator. The whole operation is atomic - |
| 9393 | * the transfer is either complete or not done at all. |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9394 | * |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9395 | * <p>Depending on the current administrator (device owner, profile owner), you have the |
| 9396 | * following expected behaviour: |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9397 | * <ul> |
| 9398 | * <li>A device owner can only be transferred to a new device owner</li> |
| 9399 | * <li>A profile owner can only be transferred to a new profile owner</li> |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9400 | * </ul> |
| 9401 | * |
arangelov | 91201bd | 2018-01-04 17:10:21 +0000 | [diff] [blame] | 9402 | * <p>Use the {@code bundle} parameter to pass data to the new administrator. The data |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9403 | * will be received in the |
arangelov | 91201bd | 2018-01-04 17:10:21 +0000 | [diff] [blame] | 9404 | * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)} |
| 9405 | * callback of the new administrator. |
| 9406 | * |
| 9407 | * <p>The transfer has failed if the original administrator is still the corresponding owner |
| 9408 | * after calling this method. |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9409 | * |
arangelov | 5149d716 | 2018-01-11 19:48:14 +0000 | [diff] [blame] | 9410 | * <p>The incoming target administrator must have the |
arangelov | c8ee263 | 2018-02-23 16:45:53 +0000 | [diff] [blame] | 9411 | * <code><support-transfer-ownership /></code> tag inside the |
| 9412 | * <code><device-admin></device-admin></code> tags in the xml file referenced by |
| 9413 | * {@link DeviceAdminReceiver#DEVICE_ADMIN_META_DATA}. Otherwise an |
| 9414 | * {@link IllegalArgumentException} will be thrown. |
arangelov | 5149d716 | 2018-01-11 19:48:14 +0000 | [diff] [blame] | 9415 | * |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9416 | * @param admin which {@link DeviceAdminReceiver} this request is associated with |
| 9417 | * @param target which {@link DeviceAdminReceiver} we want the new administrator to be |
| 9418 | * @param bundle data to be sent to the new administrator |
| 9419 | * @throws SecurityException if {@code admin} is not a device owner nor a profile owner |
arangelov | 91201bd | 2018-01-04 17:10:21 +0000 | [diff] [blame] | 9420 | * @throws IllegalArgumentException if {@code admin} or {@code target} is {@code null}, they |
| 9421 | * are components in the same package or {@code target} is not an active admin |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9422 | */ |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9423 | public void transferOwnership(@NonNull ComponentName admin, @NonNull ComponentName target, |
arangelov | 91201bd | 2018-01-04 17:10:21 +0000 | [diff] [blame] | 9424 | @Nullable PersistableBundle bundle) { |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9425 | throwIfParentInstance("transferOwnership"); |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9426 | try { |
arangelov | 8bae4ea | 2017-12-20 20:26:46 +0000 | [diff] [blame] | 9427 | mService.transferOwnership(admin, target, bundle); |
arangelov | 08841ef | 2017-11-23 15:29:42 +0000 | [diff] [blame] | 9428 | } catch (RemoteException re) { |
| 9429 | throw re.rethrowFromSystemServer(); |
| 9430 | } |
| 9431 | } |
Alex Chau | 93ae42b | 2018-01-11 15:10:12 +0000 | [diff] [blame] | 9432 | |
| 9433 | /** |
| 9434 | * Called by a device owner to specify the user session start message. This may be displayed |
| 9435 | * during a user switch. |
| 9436 | * <p> |
| 9437 | * The message should be limited to a short statement or it may be truncated. |
| 9438 | * <p> |
| 9439 | * If the message needs to be localized, it is the responsibility of the |
| 9440 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 9441 | * and set a new version of this message accordingly. |
| 9442 | * |
| 9443 | * @param admin which {@link DeviceAdminReceiver} this request is associated with. |
| 9444 | * @param startUserSessionMessage message for starting user session, or {@code null} to use |
| 9445 | * system default message. |
| 9446 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9447 | */ |
| 9448 | public void setStartUserSessionMessage( |
| 9449 | @NonNull ComponentName admin, @Nullable CharSequence startUserSessionMessage) { |
| 9450 | throwIfParentInstance("setStartUserSessionMessage"); |
| 9451 | try { |
| 9452 | mService.setStartUserSessionMessage(admin, startUserSessionMessage); |
| 9453 | } catch (RemoteException re) { |
| 9454 | throw re.rethrowFromSystemServer(); |
| 9455 | } |
| 9456 | } |
| 9457 | |
| 9458 | /** |
| 9459 | * Called by a device owner to specify the user session end message. This may be displayed |
| 9460 | * during a user switch. |
| 9461 | * <p> |
| 9462 | * The message should be limited to a short statement or it may be truncated. |
| 9463 | * <p> |
| 9464 | * If the message needs to be localized, it is the responsibility of the |
| 9465 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 9466 | * and set a new version of this message accordingly. |
| 9467 | * |
| 9468 | * @param admin which {@link DeviceAdminReceiver} this request is associated with. |
| 9469 | * @param endUserSessionMessage message for ending user session, or {@code null} to use system |
| 9470 | * default message. |
| 9471 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9472 | */ |
| 9473 | public void setEndUserSessionMessage( |
| 9474 | @NonNull ComponentName admin, @Nullable CharSequence endUserSessionMessage) { |
| 9475 | throwIfParentInstance("setEndUserSessionMessage"); |
| 9476 | try { |
| 9477 | mService.setEndUserSessionMessage(admin, endUserSessionMessage); |
| 9478 | } catch (RemoteException re) { |
| 9479 | throw re.rethrowFromSystemServer(); |
| 9480 | } |
| 9481 | } |
| 9482 | |
| 9483 | /** |
| 9484 | * Returns the user session start message. |
| 9485 | * |
| 9486 | * @param admin which {@link DeviceAdminReceiver} this request is associated with. |
| 9487 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9488 | */ |
| 9489 | public CharSequence getStartUserSessionMessage(@NonNull ComponentName admin) { |
| 9490 | throwIfParentInstance("getStartUserSessionMessage"); |
| 9491 | try { |
| 9492 | return mService.getStartUserSessionMessage(admin); |
| 9493 | } catch (RemoteException re) { |
| 9494 | throw re.rethrowFromSystemServer(); |
| 9495 | } |
| 9496 | } |
| 9497 | |
| 9498 | /** |
| 9499 | * Returns the user session end message. |
| 9500 | * |
| 9501 | * @param admin which {@link DeviceAdminReceiver} this request is associated with. |
| 9502 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9503 | */ |
| 9504 | public CharSequence getEndUserSessionMessage(@NonNull ComponentName admin) { |
| 9505 | throwIfParentInstance("getEndUserSessionMessage"); |
| 9506 | try { |
| 9507 | return mService.getEndUserSessionMessage(admin); |
| 9508 | } catch (RemoteException re) { |
| 9509 | throw re.rethrowFromSystemServer(); |
| 9510 | } |
| 9511 | } |
Vladislav Kuzkokov | 792d58f | 2018-01-15 15:04:05 +0100 | [diff] [blame] | 9512 | |
| 9513 | /** |
yuemingw | e3d9c09 | 2018-01-11 12:11:44 +0000 | [diff] [blame] | 9514 | * Called by device owner to add an override APN. |
| 9515 | * |
yuemingw | edfd36a | 2018-02-26 14:25:35 +0000 | [diff] [blame] | 9516 | * <p>This method may returns {@code -1} if {@code apnSetting} conflicts with an existing |
| 9517 | * override APN. Update the existing conflicted APN with |
| 9518 | * {@link #updateOverrideApn(ComponentName, int, ApnSetting)} instead of adding a new entry. |
yuemingw | 6586f05 | 2018-03-21 16:32:09 +0000 | [diff] [blame] | 9519 | * <p>Two override APNs are considered to conflict when all the following APIs return |
| 9520 | * the same values on both override APNs: |
| 9521 | * <ul> |
| 9522 | * <li>{@link ApnSetting#getOperatorNumeric()}</li> |
| 9523 | * <li>{@link ApnSetting#getApnName()}</li> |
yuemingw | 9bf808c | 2018-04-09 16:41:54 +0100 | [diff] [blame] | 9524 | * <li>{@link ApnSetting#getProxyAddressAsString()}</li> |
yuemingw | 6586f05 | 2018-03-21 16:32:09 +0000 | [diff] [blame] | 9525 | * <li>{@link ApnSetting#getProxyPort()}</li> |
yuemingw | 9bf808c | 2018-04-09 16:41:54 +0100 | [diff] [blame] | 9526 | * <li>{@link ApnSetting#getMmsProxyAddressAsString()}</li> |
yuemingw | 6586f05 | 2018-03-21 16:32:09 +0000 | [diff] [blame] | 9527 | * <li>{@link ApnSetting#getMmsProxyPort()}</li> |
| 9528 | * <li>{@link ApnSetting#getMmsc()}</li> |
| 9529 | * <li>{@link ApnSetting#isEnabled()}</li> |
| 9530 | * <li>{@link ApnSetting#getMvnoType()}</li> |
| 9531 | * <li>{@link ApnSetting#getProtocol()}</li> |
| 9532 | * <li>{@link ApnSetting#getRoamingProtocol()}</li> |
| 9533 | * </ul> |
yuemingw | edfd36a | 2018-02-26 14:25:35 +0000 | [diff] [blame] | 9534 | * |
yuemingw | e3d9c09 | 2018-01-11 12:11:44 +0000 | [diff] [blame] | 9535 | * @param admin which {@link DeviceAdminReceiver} this request is associated with |
| 9536 | * @param apnSetting the override APN to insert |
| 9537 | * @return The {@code id} of inserted override APN. Or {@code -1} when failed to insert into |
| 9538 | * the database. |
| 9539 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9540 | * |
| 9541 | * @see #setOverrideApnsEnabled(ComponentName, boolean) |
| 9542 | */ |
| 9543 | public int addOverrideApn(@NonNull ComponentName admin, @NonNull ApnSetting apnSetting) { |
| 9544 | throwIfParentInstance("addOverrideApn"); |
| 9545 | if (mService != null) { |
| 9546 | try { |
| 9547 | return mService.addOverrideApn(admin, apnSetting); |
| 9548 | } catch (RemoteException e) { |
| 9549 | throw e.rethrowFromSystemServer(); |
| 9550 | } |
| 9551 | } |
| 9552 | return -1; |
| 9553 | } |
| 9554 | |
| 9555 | /** |
| 9556 | * Called by device owner to update an override APN. |
| 9557 | * |
yuemingw | edfd36a | 2018-02-26 14:25:35 +0000 | [diff] [blame] | 9558 | * <p>This method may returns {@code false} if there is no override APN with the given |
| 9559 | * {@code apnId}. |
| 9560 | * <p>This method may also returns {@code false} if {@code apnSetting} conflicts with an |
| 9561 | * existing override APN. Update the existing conflicted APN instead. |
yuemingw | 6586f05 | 2018-03-21 16:32:09 +0000 | [diff] [blame] | 9562 | * <p>See {@link #addOverrideApn} for the definition of conflict. |
yuemingw | edfd36a | 2018-02-26 14:25:35 +0000 | [diff] [blame] | 9563 | * |
yuemingw | e3d9c09 | 2018-01-11 12:11:44 +0000 | [diff] [blame] | 9564 | * @param admin which {@link DeviceAdminReceiver} this request is associated with |
| 9565 | * @param apnId the {@code id} of the override APN to update |
| 9566 | * @param apnSetting the override APN to update |
| 9567 | * @return {@code true} if the required override APN is successfully updated, |
| 9568 | * {@code false} otherwise. |
| 9569 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9570 | * |
| 9571 | * @see #setOverrideApnsEnabled(ComponentName, boolean) |
| 9572 | */ |
| 9573 | public boolean updateOverrideApn(@NonNull ComponentName admin, int apnId, |
| 9574 | @NonNull ApnSetting apnSetting) { |
| 9575 | throwIfParentInstance("updateOverrideApn"); |
| 9576 | if (mService != null) { |
| 9577 | try { |
| 9578 | return mService.updateOverrideApn(admin, apnId, apnSetting); |
| 9579 | } catch (RemoteException e) { |
| 9580 | throw e.rethrowFromSystemServer(); |
| 9581 | } |
| 9582 | } |
| 9583 | return false; |
| 9584 | } |
| 9585 | |
| 9586 | /** |
| 9587 | * Called by device owner to remove an override APN. |
| 9588 | * |
yuemingw | edfd36a | 2018-02-26 14:25:35 +0000 | [diff] [blame] | 9589 | * <p>This method may returns {@code false} if there is no override APN with the given |
| 9590 | * {@code apnId}. |
| 9591 | * |
yuemingw | e3d9c09 | 2018-01-11 12:11:44 +0000 | [diff] [blame] | 9592 | * @param admin which {@link DeviceAdminReceiver} this request is associated with |
| 9593 | * @param apnId the {@code id} of the override APN to remove |
| 9594 | * @return {@code true} if the required override APN is successfully removed, {@code false} |
| 9595 | * otherwise. |
| 9596 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9597 | * |
| 9598 | * @see #setOverrideApnsEnabled(ComponentName, boolean) |
| 9599 | */ |
| 9600 | public boolean removeOverrideApn(@NonNull ComponentName admin, int apnId) { |
| 9601 | throwIfParentInstance("removeOverrideApn"); |
| 9602 | if (mService != null) { |
| 9603 | try { |
| 9604 | return mService.removeOverrideApn(admin, apnId); |
| 9605 | } catch (RemoteException e) { |
| 9606 | throw e.rethrowFromSystemServer(); |
| 9607 | } |
| 9608 | } |
| 9609 | return false; |
| 9610 | } |
| 9611 | |
| 9612 | /** |
| 9613 | * Called by device owner to get all override APNs inserted by device owner. |
| 9614 | * |
| 9615 | * @param admin which {@link DeviceAdminReceiver} this request is associated with |
| 9616 | * @return A list of override APNs inserted by device owner. |
| 9617 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9618 | * |
| 9619 | * @see #setOverrideApnsEnabled(ComponentName, boolean) |
| 9620 | */ |
| 9621 | public List<ApnSetting> getOverrideApns(@NonNull ComponentName admin) { |
| 9622 | throwIfParentInstance("getOverrideApns"); |
| 9623 | if (mService != null) { |
| 9624 | try { |
| 9625 | return mService.getOverrideApns(admin); |
| 9626 | } catch (RemoteException e) { |
| 9627 | throw e.rethrowFromSystemServer(); |
| 9628 | } |
| 9629 | } |
| 9630 | return Collections.emptyList(); |
| 9631 | } |
| 9632 | |
| 9633 | /** |
| 9634 | * Called by device owner to set if override APNs should be enabled. |
| 9635 | * <p> Override APNs are separated from other APNs on the device, and can only be inserted or |
| 9636 | * modified by the device owner. When enabled, only override APNs are in use, any other APNs |
| 9637 | * are ignored. |
| 9638 | * |
| 9639 | * @param admin which {@link DeviceAdminReceiver} this request is associated with |
| 9640 | * @param enabled {@code true} if override APNs should be enabled, {@code false} otherwise |
| 9641 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9642 | */ |
| 9643 | public void setOverrideApnsEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 9644 | throwIfParentInstance("setOverrideApnEnabled"); |
| 9645 | if (mService != null) { |
| 9646 | try { |
| 9647 | mService.setOverrideApnsEnabled(admin, enabled); |
| 9648 | } catch (RemoteException e) { |
| 9649 | throw e.rethrowFromSystemServer(); |
| 9650 | } |
| 9651 | } |
| 9652 | } |
| 9653 | |
| 9654 | /** |
| 9655 | * Called by device owner to check if override APNs are currently enabled. |
| 9656 | * |
| 9657 | * @param admin which {@link DeviceAdminReceiver} this request is associated with |
| 9658 | * @return {@code true} if override APNs are currently enabled, {@code false} otherwise. |
| 9659 | * @throws SecurityException if {@code admin} is not a device owner. |
| 9660 | * |
| 9661 | * @see #setOverrideApnsEnabled(ComponentName, boolean) |
| 9662 | */ |
| 9663 | public boolean isOverrideApnEnabled(@NonNull ComponentName admin) { |
| 9664 | throwIfParentInstance("isOverrideApnEnabled"); |
| 9665 | if (mService != null) { |
| 9666 | try { |
| 9667 | return mService.isOverrideApnEnabled(admin); |
| 9668 | } catch (RemoteException e) { |
| 9669 | throw e.rethrowFromSystemServer(); |
| 9670 | } |
| 9671 | } |
| 9672 | return false; |
| 9673 | } |
arangelov | 91201bd | 2018-01-04 17:10:21 +0000 | [diff] [blame] | 9674 | |
| 9675 | /** |
| 9676 | * Returns the data passed from the current administrator to the new administrator during an |
| 9677 | * ownership transfer. This is the same {@code bundle} passed in |
arangelov | dc63bd7 | 2018-02-22 12:36:23 +0000 | [diff] [blame] | 9678 | * {@link #transferOwnership(ComponentName, ComponentName, PersistableBundle)}. The bundle is |
| 9679 | * persisted until the profile owner or device owner is removed. |
| 9680 | * |
| 9681 | * <p>This is the same <code>bundle</code> received in the |
| 9682 | * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}. |
| 9683 | * Use this method to retrieve it after the transfer as long as the new administrator is the |
| 9684 | * active device or profile owner. |
arangelov | 91201bd | 2018-01-04 17:10:21 +0000 | [diff] [blame] | 9685 | * |
| 9686 | * <p>Returns <code>null</code> if no ownership transfer was started for the calling user. |
| 9687 | * |
| 9688 | * @see #transferOwnership |
| 9689 | * @see DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle) |
arangelov | dc63bd7 | 2018-02-22 12:36:23 +0000 | [diff] [blame] | 9690 | * @throws SecurityException if the caller is not a device or profile owner. |
arangelov | 91201bd | 2018-01-04 17:10:21 +0000 | [diff] [blame] | 9691 | */ |
| 9692 | @Nullable |
| 9693 | public PersistableBundle getTransferOwnershipBundle() { |
| 9694 | throwIfParentInstance("getTransferOwnershipBundle"); |
| 9695 | try { |
| 9696 | return mService.getTransferOwnershipBundle(); |
| 9697 | } catch (RemoteException re) { |
| 9698 | throw re.rethrowFromSystemServer(); |
| 9699 | } |
| 9700 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 9701 | } |