Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
| 25 | import android.annotation.SdkConstant.SdkConstantType; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 26 | import android.annotation.SuppressLint; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 27 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 28 | import android.annotation.SystemService; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 29 | import android.annotation.TestApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 30 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 31 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 32 | import android.app.Activity; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 33 | import android.app.IServiceConnection; |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 34 | import android.app.KeyguardManager; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 35 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 36 | import android.content.ComponentName; |
| 37 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 38 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 39 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 40 | import android.content.ServiceConnection; |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 41 | import android.content.pm.ApplicationInfo; |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 42 | import android.content.pm.IPackageDataObserver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 43 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 44 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 45 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 46 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 47 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 48 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 49 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 50 | import android.os.Bundle; |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 51 | import android.os.Handler; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 52 | import android.os.Parcelable; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 53 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 54 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 55 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 56 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 58 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 59 | import android.provider.ContactsContract.Directory; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 60 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 61 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 62 | import android.telephony.TelephonyManager; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 63 | import android.util.ArraySet; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 64 | import android.util.Log; |
| 65 | |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 66 | import com.android.internal.R; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 67 | import com.android.internal.annotations.VisibleForTesting; |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 68 | import com.android.internal.util.Preconditions; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 69 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 70 | |
| 71 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 72 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 73 | import java.lang.annotation.Retention; |
| 74 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 75 | import java.net.InetSocketAddress; |
| 76 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 77 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 78 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 79 | import java.security.PrivateKey; |
| 80 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 81 | import java.security.cert.CertificateException; |
| 82 | import java.security.cert.CertificateFactory; |
| 83 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 84 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 85 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 86 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 87 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 88 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 89 | import java.util.List; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 90 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 93 | * 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] | 94 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 95 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 96 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 97 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 98 | * application calling an api may only pass as an argument a device administrator component it |
| 99 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 100 | * <div class="special reference"> |
| 101 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 102 | * <p> |
| 103 | * For more information about managing policies for device administration, read the <a href= |
| 104 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 105 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 106 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 107 | @SystemService(Context.DEVICE_POLICY_SERVICE) |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 108 | public class DevicePolicyManager { |
| 109 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 110 | |
| 111 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 112 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 113 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 114 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 115 | /** @hide */ |
| 116 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 117 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 120 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 121 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 122 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 123 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 124 | mContext = context; |
| 125 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 126 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 129 | /** @hide test will override it. */ |
| 130 | @VisibleForTesting |
| 131 | protected int myUserId() { |
| 132 | return UserHandle.myUserId(); |
| 133 | } |
| 134 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 135 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 136 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 137 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 138 | * <p>A managed profile allows data separation for example for the usage of a |
| 139 | * device as a personal and corporate device. The user which provisioning is started from and |
| 140 | * the managed profile share a launcher. |
| 141 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 142 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 143 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 144 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 145 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 146 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 147 | * {@link #isProvisioningAllowed(String)}. |
| 148 | * |
| 149 | * <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] | 150 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 151 | * 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] | 152 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 153 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 154 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 155 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 156 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 157 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 158 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 159 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 160 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 161 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 162 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 163 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 164 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 165 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 166 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 167 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 168 | * <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] | 169 | * in the provisioning intent. The |
| 170 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 171 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 172 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 173 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 174 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 175 | * completed, along with the above broadcast, activity intent |
Esteban Talavera | 4047bae | 2017-06-28 11:03:09 +0100 | [diff] [blame] | 176 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner. |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 177 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 178 | * <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] | 179 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 180 | * |
| 181 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 182 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 183 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 184 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 185 | * 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] | 186 | */ |
| 187 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 188 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 189 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 190 | |
| 191 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 192 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 193 | * |
| 194 | * <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] | 195 | * 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] | 196 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 197 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 198 | * allowed. |
| 199 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 200 | * <p>The intent contains the following extras: |
| 201 | * <ul> |
| 202 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 203 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 204 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 205 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 206 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 207 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 208 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 209 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 210 | * |
| 211 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 212 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 213 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 214 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 215 | * 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] | 216 | * |
| 217 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 218 | */ |
| 219 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 220 | public static final String ACTION_PROVISION_MANAGED_USER |
| 221 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 222 | |
| 223 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 224 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 225 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 226 | * |
| 227 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 228 | * A device owner has full control over the device. The device owner can not be modified by the |
| 229 | * user. |
| 230 | * |
| 231 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 232 | * employee or client. |
| 233 | * |
| 234 | * <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] | 235 | * It is possible to check if provisioning is allowed or not by querying the method |
| 236 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 237 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 238 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 239 | * <ul> |
| 240 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 241 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 242 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 243 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 244 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 245 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 246 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 247 | * </ul> |
| 248 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 249 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 250 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 251 | * device owner. |
| 252 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 253 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 254 | * completed, along with the above broadcast, activity intent |
| 255 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 256 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 257 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 258 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 259 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 260 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 261 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 262 | * 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] | 263 | */ |
| 264 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 265 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 266 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 267 | |
| 268 | /** |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 269 | * Activity action: launch when user provisioning completed, i.e. |
| 270 | * {@link #getUserProvisioningState()} returns one of the complete state. |
| 271 | * |
| 272 | * <p> Please note that the API behavior is not necessarily consistent across various releases, |
| 273 | * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default |
| 274 | * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only. |
| 275 | * |
| 276 | * <p> The activity must be protected by permission |
| 277 | * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold |
| 278 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched. |
| 279 | * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the |
| 280 | * components are not started by this intent. |
| 281 | * @hide |
| 282 | */ |
| 283 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
Jeff Sharkey | 9039636 | 2017-06-12 16:26:53 -0600 | [diff] [blame] | 284 | @SystemApi |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 285 | public static final String ACTION_STATE_USER_SETUP_COMPLETE = |
| 286 | "android.app.action.STATE_USER_SETUP_COMPLETE"; |
| 287 | |
| 288 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 289 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 290 | * |
| 291 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 292 | * the device. A device owner has full control over the device. The device owner can not be |
| 293 | * modified by the user and the only way of resetting the device is via factory reset. |
| 294 | * |
| 295 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 296 | * employee or client. |
| 297 | * |
| 298 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 299 | * |
| 300 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 301 | * by a privileged app with the permission |
| 302 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 303 | * |
| 304 | * <p>The provisioning intent contains the following properties: |
| 305 | * <ul> |
| 306 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 307 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 308 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 309 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 310 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 312 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 314 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 315 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 316 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 317 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 318 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 319 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 320 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 321 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 322 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 323 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 324 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 325 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 326 | * |
| 327 | * @hide |
| 328 | */ |
| 329 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 330 | @SystemApi |
| 331 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 332 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 333 | |
| 334 | /** |
| 335 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 336 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 337 | * |
| 338 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 339 | * management state that is distinct from that reached by |
| 340 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 341 | * user, and only has control over device-wide policies, not individual users and their data. |
| 342 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 343 | * this form of device management. |
| 344 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 345 | * <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] | 346 | * A device owner has full control over the device. The device owner can not be modified by the |
| 347 | * user. |
| 348 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 349 | * <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] | 350 | * employee or client. |
| 351 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 352 | * <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] | 353 | * It is possible to check if provisioning is allowed or not by querying the method |
| 354 | * {@link #isProvisioningAllowed(String)}. |
| 355 | * |
| 356 | * <p>The intent contains the following extras: |
| 357 | * <ul> |
| 358 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 359 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 360 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 361 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 362 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 363 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 364 | * </ul> |
| 365 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 366 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 367 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 368 | * device owner. |
| 369 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 370 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 371 | * completed, along with the above broadcast, activity intent |
| 372 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 373 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 374 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 375 | * |
| 376 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 377 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 378 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 379 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 380 | * |
| 381 | * @hide |
| 382 | */ |
| 383 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 384 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 385 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 386 | |
| 387 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 388 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 389 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 390 | * <ul> |
| 391 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 392 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 393 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 394 | * </ul> |
| 395 | * |
| 396 | * @hide |
| 397 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 398 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 399 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 400 | public static final String ACTION_PROVISION_FINALIZATION |
| 401 | = "android.app.action.PROVISION_FINALIZATION"; |
| 402 | |
| 403 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 404 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 405 | * |
| 406 | * @hide |
| 407 | */ |
| 408 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 409 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 410 | |
| 411 | /** |
| 412 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 413 | * |
| 414 | * @hide |
| 415 | */ |
| 416 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 417 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 418 | |
| 419 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 420 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 421 | * |
| 422 | * @hide |
| 423 | */ |
| 424 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 425 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 426 | |
| 427 | /** |
| 428 | * Extra for shared bugreport's SHA-256 hash. |
| 429 | * |
| 430 | * @hide |
| 431 | */ |
| 432 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 433 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 434 | |
| 435 | /** |
| 436 | * Extra for remote bugreport notification shown type. |
| 437 | * |
| 438 | * @hide |
| 439 | */ |
| 440 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 441 | "android.app.extra.bugreport_notification_type"; |
| 442 | |
| 443 | /** |
| 444 | * Notification type for a started remote bugreport flow. |
| 445 | * |
| 446 | * @hide |
| 447 | */ |
| 448 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 449 | |
| 450 | /** |
| 451 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 452 | * being taken. |
| 453 | * |
| 454 | * @hide |
| 455 | */ |
| 456 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 457 | |
| 458 | /** |
| 459 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 460 | * |
| 461 | * @hide |
| 462 | */ |
| 463 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 464 | |
| 465 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 466 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 467 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 468 | * |
| 469 | * @hide |
| 470 | */ |
| 471 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 472 | |
| 473 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 474 | * 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] | 475 | * allows a mobile device management application or NFC programmer application which starts |
| 476 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 477 | * <p> |
| 478 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 479 | * sends the intent to pass data to itself on the newly created profile. |
| 480 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 481 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 482 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 483 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 484 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 485 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 486 | * management application after provisioning. |
| 487 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 488 | * <p> |
| 489 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 490 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 491 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 492 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 493 | */ |
| 494 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 495 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 496 | |
| 497 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 498 | * A String extra holding the package name of the mobile device management application that |
| 499 | * will be set as the profile owner or device owner. |
| 500 | * |
| 501 | * <p>If an application starts provisioning directly via an intent with action |
| 502 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 503 | * application that started provisioning. The package will be set as profile owner in that case. |
| 504 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 505 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 506 | * 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] | 507 | * |
| 508 | * <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] | 509 | * 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] | 510 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 511 | * @see DeviceAdminReceiver |
| 512 | * @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] | 513 | * supported, but only if there is only one device admin receiver in the package that requires |
| 514 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 515 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 516 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 517 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 518 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 519 | |
| 520 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 521 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 522 | * application that will be set as the profile owner or device owner and active admin. |
| 523 | * |
| 524 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 525 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 526 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 527 | * 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] | 528 | * |
| 529 | * <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] | 530 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 531 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 532 | * {@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] | 533 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 534 | * |
| 535 | * @see DeviceAdminReceiver |
| 536 | */ |
| 537 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 538 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 539 | |
| 540 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 541 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 542 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 543 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 544 | * |
| 545 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 546 | */ |
| 547 | |
| 548 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 549 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 550 | |
| 551 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 552 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 553 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 554 | * the account will not be removed from the primary user after it is migrated to the newly |
| 555 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 556 | * |
| 557 | * <p> Defaults to {@code false} |
| 558 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 559 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 560 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 561 | */ |
| 562 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 563 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 564 | |
| 565 | /** |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 566 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the |
| 567 | * device. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 568 | */ |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 569 | @Deprecated |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 570 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 571 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 572 | |
| 573 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 574 | * A integer extra indicating the predominant color to show during the provisioning. |
| 575 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 576 | * |
| 577 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 578 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 579 | */ |
| 580 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 581 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 582 | |
| 583 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 584 | * 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] | 585 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 586 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 587 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 588 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 589 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 590 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 591 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 592 | |
| 593 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 594 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 595 | * will be set to. |
| 596 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 597 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 598 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 599 | */ |
| 600 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 601 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | |
| 603 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 604 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 605 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 606 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 607 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 608 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 609 | */ |
| 610 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 611 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | |
| 613 | /** |
| 614 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 615 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 616 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 617 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 618 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 619 | */ |
| 620 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 621 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 625 | * owner provisioning for downloading the mobile device management application. |
| 626 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 627 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 628 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 629 | */ |
| 630 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 631 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 632 | |
| 633 | /** |
| 634 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 635 | * is hidden or not. |
| 636 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 637 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 638 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 639 | */ |
| 640 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 641 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 642 | |
| 643 | /** |
| 644 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 645 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 646 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 647 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 648 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 649 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 650 | */ |
| 651 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 652 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 653 | |
| 654 | /** |
| 655 | * A String extra holding the password of the wifi network in |
| 656 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 657 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 658 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 659 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 660 | */ |
| 661 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 662 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 663 | |
| 664 | /** |
| 665 | * A String extra holding the proxy host for the wifi network in |
| 666 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 667 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 668 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 669 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 670 | */ |
| 671 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 672 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 673 | |
| 674 | /** |
| 675 | * An int extra holding the proxy port for the wifi network in |
| 676 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 677 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 678 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 679 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 680 | */ |
| 681 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 682 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 683 | |
| 684 | /** |
| 685 | * A String extra holding the proxy bypass for the wifi network in |
| 686 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 687 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 688 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 689 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 690 | */ |
| 691 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 692 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 693 | |
| 694 | /** |
| 695 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 696 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 697 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 698 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 699 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 700 | */ |
| 701 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 702 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 703 | |
| 704 | /** |
| 705 | * A String extra holding a url that specifies the download location of the device admin |
| 706 | * package. When not provided it is assumed that the device admin package is already installed. |
| 707 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 708 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 709 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 710 | */ |
| 711 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 712 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 713 | |
| 714 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 715 | * A String extra holding the localized name of the organization under management. |
| 716 | * |
| 717 | * The name is displayed only during provisioning. |
| 718 | * |
| 719 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 720 | * |
| 721 | * @hide |
| 722 | */ |
| 723 | @SystemApi |
| 724 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 725 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 726 | |
| 727 | /** |
Alejandro Fernández | bfd6193 | 2017-04-04 19:33:01 +0100 | [diff] [blame] | 728 | * A String extra holding a url to the website of the device provider so the user can open it |
| 729 | * 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] | 730 | * |
| 731 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 732 | * |
| 733 | * @hide |
| 734 | */ |
| 735 | @SystemApi |
| 736 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 737 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 738 | |
| 739 | /** |
| 740 | * A String extra holding the localized name of the device admin package. It should be the same |
| 741 | * as the app label of the package. |
| 742 | * |
| 743 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 744 | * |
| 745 | * @hide |
| 746 | */ |
| 747 | @SystemApi |
| 748 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 749 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 750 | |
| 751 | /** |
| 752 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 753 | * shown during the provisioning. |
| 754 | * <h5>The following URI schemes are accepted:</h5> |
| 755 | * <ul> |
| 756 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 757 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 758 | * </ul> |
| 759 | * |
| 760 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 761 | * pixel density for the device. |
| 762 | * |
| 763 | * <p> If a content: URI is passed, the intent should have the flag |
| 764 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 765 | * {@link android.content.ClipData} of the intent too. |
| 766 | * |
| 767 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 768 | * |
| 769 | * @hide |
| 770 | */ |
| 771 | @SystemApi |
| 772 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 773 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 774 | |
| 775 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 776 | * An int extra holding a minimum required version code for the device admin package. If the |
| 777 | * device admin is already installed on the device, it will only be re-downloaded from |
| 778 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 779 | * installed package is less than this version code. |
| 780 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 781 | * <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] | 782 | * provisioning via an NFC bump. |
| 783 | */ |
| 784 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 785 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 786 | |
| 787 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 788 | * A String extra holding a http cookie header which should be used in the http request to the |
| 789 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 790 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 791 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 792 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 793 | */ |
| 794 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 795 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 796 | |
| 797 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 798 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 799 | * the file at download location specified in |
| 800 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 801 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 802 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 803 | * 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] | 804 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 805 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 806 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 807 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 808 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 809 | * |
| 810 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 811 | * 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] | 812 | * 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] | 813 | * 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] | 814 | */ |
| 815 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 816 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 817 | |
| 818 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 819 | * 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] | 820 | * android package archive at the download location specified in {@link |
| 821 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 822 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 823 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 824 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 825 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 826 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 827 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 828 | * 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] | 829 | * the download location. If the checksum does not match an error will be shown to the user and |
| 830 | * the user will be asked to factory reset the device. |
| 831 | * |
| 832 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 833 | * provisioning via an NFC bump. |
| 834 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 835 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 836 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 837 | |
| 838 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 839 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 840 | * has completed successfully. |
| 841 | * |
| 842 | * <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] | 843 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 844 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 845 | * <p>This intent will contain the following extras |
| 846 | * <ul> |
| 847 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 848 | * profile.</li> |
| 849 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 850 | * be migrated at provisioning time, if any.</li> |
| 851 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 852 | */ |
| 853 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 854 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 855 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 856 | |
| 857 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 858 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 859 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 860 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 861 | * delivered faster as it's an activity intent. |
| 862 | * |
Esteban Talavera | 4047bae | 2017-06-28 11:03:09 +0100 | [diff] [blame] | 863 | * <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] | 864 | * |
| 865 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 866 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 867 | */ |
| 868 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 869 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 870 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 871 | |
| 872 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 873 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 874 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 875 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 876 | * <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] | 877 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 878 | * |
| 879 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 880 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 881 | */ |
| 882 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 883 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 884 | |
| 885 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 886 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 887 | * provisioning. If this extra is not passed, a default image will be shown. |
| 888 | * <h5>The following URI schemes are accepted:</h5> |
| 889 | * <ul> |
| 890 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 891 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 892 | * </ul> |
| 893 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 894 | * <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] | 895 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 896 | * |
| 897 | * <p> If a content: URI is passed, the intent should have the flag |
| 898 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 899 | * {@link android.content.ClipData} of the intent too. |
| 900 | * |
| 901 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 902 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 903 | */ |
| 904 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 905 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 906 | |
| 907 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 908 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 909 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 910 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 911 | * content. |
| 912 | * |
| 913 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 914 | * management application (MDM), and one disclaimer from the organization. |
| 915 | * |
| 916 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 917 | * |
| 918 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 919 | * |
| 920 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 921 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 922 | */ |
| 923 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 924 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 925 | |
| 926 | /** |
| 927 | * A String extra of localized disclaimer header. |
| 928 | * |
| 929 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 930 | * or the organization name. |
| 931 | * |
| 932 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 933 | * |
| 934 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 935 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 936 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 937 | * |
| 938 | * <pre> |
| 939 | * <meta-data |
| 940 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 941 | * android:resource="@string/disclaimer_header" |
| 942 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 943 | */ |
| 944 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 945 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 946 | |
| 947 | /** |
| 948 | * A {@link Uri} extra pointing to disclaimer content. |
| 949 | * |
| 950 | * <h5>The following URI schemes are accepted:</h5> |
| 951 | * <ul> |
| 952 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 953 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 954 | * </ul> |
| 955 | * |
| 956 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 957 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 958 | * {@link android.widget.TextView}. |
| 959 | * |
| 960 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 961 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 962 | * {@link android.content.ClipData} of the intent too. |
| 963 | * |
| 964 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 965 | * |
| 966 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 967 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 968 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 969 | * |
| 970 | * <pre> |
| 971 | * <meta-data |
| 972 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 973 | * android:resource="@string/disclaimer_content" |
| 974 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 975 | */ |
| 976 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 977 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 978 | |
| 979 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 980 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 981 | * during setup-wizard. |
| 982 | * |
| 983 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 984 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 985 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 986 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 987 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 988 | * |
| 989 | * @hide |
| 990 | */ |
| 991 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 992 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 993 | |
| 994 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 995 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 996 | * skipped. If unspecified, defaults to {@code false}. |
| 997 | * |
| 998 | * It can only be used by an existing device owner trying to create a managed profile via |
| 999 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 1000 | */ |
| 1001 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 1002 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 1003 | |
| 1004 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1005 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1006 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 1007 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 1008 | * A device owner has full control over the device. The device owner can not be modified by the |
| 1009 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 1010 | * reset. |
| 1011 | * |
| 1012 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 1013 | * employee or client. |
| 1014 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1015 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1016 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 1017 | * <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] | 1018 | * contains the following properties: |
| 1019 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1020 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 1021 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 1022 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1023 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1024 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1025 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1026 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1027 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1028 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1029 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1030 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1031 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1032 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1033 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1034 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1035 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1036 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1037 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1038 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1039 | * 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] | 1040 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1041 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1042 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1043 | */ |
| 1044 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1045 | = "application/com.android.managedprovisioning"; |
| 1046 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1047 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1048 | * Activity action: ask the user to add a new device administrator to the system. |
| 1049 | * The desired policy is the ComponentName of the policy in the |
| 1050 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1051 | * bring the user through adding the device administrator to the system (or |
| 1052 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1053 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1054 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1055 | * field to provide the user with additional explanation (in addition |
| 1056 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1057 | * |
| 1058 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1059 | * user intervention). However, if your administrator has been updated and is requesting |
| 1060 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1061 | * 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] | 1062 | */ |
| 1063 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1064 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1065 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1066 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1067 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1068 | * @hide |
| 1069 | * 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] | 1070 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1071 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1072 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1073 | * 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] | 1074 | * to remotely control restrictions on the user. |
| 1075 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1076 | * <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] | 1077 | * result of whether or not the user approved the action. If approved, the result will |
| 1078 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1079 | * as a profile owner. |
| 1080 | * |
| 1081 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1082 | * field to provide the user with additional explanation (in addition |
| 1083 | * to your component's description) about what is being added. |
| 1084 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1085 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1086 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1087 | */ |
| 1088 | @SystemApi |
| 1089 | public static final String ACTION_SET_PROFILE_OWNER |
| 1090 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1091 | |
| 1092 | /** |
| 1093 | * @hide |
| 1094 | * Name of the profile owner admin that controls the user. |
| 1095 | */ |
| 1096 | @SystemApi |
| 1097 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1098 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1099 | |
| 1100 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1101 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1102 | * 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] | 1103 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1104 | * @hide |
| 1105 | */ |
| 1106 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1107 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1108 | |
| 1109 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1110 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1111 | * |
| 1112 | * This broadcast is sent only to the primary user. |
| 1113 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1114 | */ |
| 1115 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1116 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1117 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1118 | |
| 1119 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1120 | * The ComponentName of the administrator component. |
| 1121 | * |
| 1122 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1123 | */ |
| 1124 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1125 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1126 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1127 | * An optional CharSequence providing additional explanation for why the |
| 1128 | * admin is being added. |
| 1129 | * |
| 1130 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1131 | */ |
| 1132 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1133 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1134 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1135 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1136 | * {@link #createAdminSupportIntent(String)}. |
| 1137 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1138 | */ |
| 1139 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1140 | |
| 1141 | /** |
| 1142 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1143 | * {@link #createAdminSupportIntent(String)}. |
| 1144 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1145 | */ |
| 1146 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1147 | |
| 1148 | /** |
| 1149 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1150 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
| 1151 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 1152 | * @see #createAdminSupportIntent(String) |
| 1153 | * @hide |
| 1154 | */ |
| 1155 | @TestApi |
| 1156 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1157 | |
| 1158 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1159 | * Activity action: have the user enter a new password. This activity should |
| 1160 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1161 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1162 | * enter a new password that meets the current requirements. You can use |
| 1163 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1164 | * have the user select a new password in order to meet the current |
| 1165 | * constraints. Upon being resumed from this activity, you can check the new |
| 1166 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1167 | * |
| 1168 | * If the intent is launched from within a managed profile with a profile |
| 1169 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1170 | * this will trigger entering a new password for the parent of the profile. |
| 1171 | * For all other cases it will trigger entering a new password for the user |
| 1172 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1173 | * |
| 1174 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1175 | */ |
| 1176 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1177 | public static final String ACTION_SET_NEW_PASSWORD |
| 1178 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1179 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1180 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1181 | * Activity action: have the user enter a new password for the parent profile. |
| 1182 | * If the intent is launched from within a managed profile, this will trigger |
| 1183 | * entering a new password for the parent of the profile. In all other cases |
| 1184 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1185 | */ |
| 1186 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1187 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1188 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1189 | |
| 1190 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1191 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1192 | * Network logging was enabled and the user tapped the notification. |
| 1193 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1194 | * @hide |
| 1195 | */ |
| 1196 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1197 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1198 | |
| 1199 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1200 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1201 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1202 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1203 | * |
| 1204 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1205 | */ |
| 1206 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1207 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1208 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1209 | |
| 1210 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1211 | * 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] | 1212 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1213 | */ |
| 1214 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1215 | |
| 1216 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1217 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1218 | * the parent profile to access intents sent from the managed profile. |
| 1219 | * That is, when an app in the managed profile calls |
| 1220 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1221 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1222 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1223 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1224 | |
| 1225 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1226 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1227 | * the managed profile to access intents sent from the parent profile. |
| 1228 | * That is, when an app in the parent profile calls |
| 1229 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1230 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1231 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1232 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1233 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1234 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1235 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1236 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1237 | */ |
| 1238 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1239 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1240 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1241 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1242 | /** |
| 1243 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1244 | * Already granted or denied permissions are not affected by this. |
| 1245 | */ |
| 1246 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1247 | |
| 1248 | /** |
| 1249 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1250 | * Already granted or denied permissions are not affected by this. |
| 1251 | */ |
| 1252 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1253 | |
| 1254 | /** |
| 1255 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1256 | * Already granted or denied permissions are not affected by this. |
| 1257 | */ |
| 1258 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1259 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1260 | /** |
| 1261 | * Runtime permission state: The user can manage the permission |
| 1262 | * through the UI. |
| 1263 | */ |
| 1264 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1265 | |
| 1266 | /** |
| 1267 | * Runtime permission state: The permission is granted to the app |
| 1268 | * and the user cannot manage the permission through the UI. |
| 1269 | */ |
| 1270 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1271 | |
| 1272 | /** |
| 1273 | * Runtime permission state: The permission is denied to the app |
| 1274 | * and the user cannot manage the permission through the UI. |
| 1275 | */ |
| 1276 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1277 | |
| 1278 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1279 | * Delegation of certificate installation and management. This scope grants access to the |
| 1280 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1281 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1282 | */ |
| 1283 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1284 | |
| 1285 | /** |
| 1286 | * Delegation of application restrictions management. This scope grants access to the |
| 1287 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1288 | */ |
| 1289 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1290 | |
| 1291 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1292 | * Delegation of application uninstall block. This scope grants access to the |
| 1293 | * {@link #setUninstallBlocked} API. |
| 1294 | */ |
| 1295 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1296 | |
| 1297 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1298 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1299 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1300 | * and {@link #setPermissionGrantState} APIs. |
| 1301 | */ |
| 1302 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1303 | |
| 1304 | /** |
| 1305 | * Delegation of package access state. This scope grants access to the |
| 1306 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1307 | * {@link #setPackagesSuspended} APIs. |
| 1308 | */ |
| 1309 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1310 | |
| 1311 | /** |
| 1312 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1313 | * API. |
| 1314 | */ |
| 1315 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1316 | |
| 1317 | /** |
| 1318 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1319 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1320 | * @hide |
| 1321 | */ |
| 1322 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1323 | "delegation-keep-uninstalled-packages"; |
| 1324 | |
| 1325 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1326 | * No management for current user in-effect. This is the default. |
| 1327 | * @hide |
| 1328 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1329 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1330 | public static final int STATE_USER_UNMANAGED = 0; |
| 1331 | |
| 1332 | /** |
| 1333 | * Management partially setup, user setup needs to be completed. |
| 1334 | * @hide |
| 1335 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1336 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1337 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1338 | |
| 1339 | /** |
| 1340 | * Management partially setup, user setup completed. |
| 1341 | * @hide |
| 1342 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1343 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1344 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1345 | |
| 1346 | /** |
| 1347 | * Management setup and active on current user. |
| 1348 | * @hide |
| 1349 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1350 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1351 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1352 | |
| 1353 | /** |
| 1354 | * Management partially setup on a managed profile. |
| 1355 | * @hide |
| 1356 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1357 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1358 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1359 | |
| 1360 | /** |
| 1361 | * @hide |
| 1362 | */ |
| 1363 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1364 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1365 | @Retention(RetentionPolicy.SOURCE) |
| 1366 | public @interface UserProvisioningState {} |
| 1367 | |
| 1368 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1369 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1370 | * |
| 1371 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1372 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1373 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1374 | * |
| 1375 | * @hide |
| 1376 | */ |
| 1377 | public static final int CODE_OK = 0; |
| 1378 | |
| 1379 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1380 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1381 | * |
| 1382 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1383 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1384 | * owner. |
| 1385 | * |
| 1386 | * @hide |
| 1387 | */ |
| 1388 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1389 | |
| 1390 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1391 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1392 | * |
| 1393 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1394 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1395 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1396 | * |
| 1397 | * @hide |
| 1398 | */ |
| 1399 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1400 | |
| 1401 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1402 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1403 | * |
| 1404 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1405 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1406 | * |
| 1407 | * @hide |
| 1408 | */ |
| 1409 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1410 | |
| 1411 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1412 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1413 | * |
| 1414 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1415 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1416 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1417 | * |
| 1418 | * @hide |
| 1419 | */ |
| 1420 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1421 | |
| 1422 | /** |
| 1423 | * Code used to indicate that the device also has a user other than the system user. |
| 1424 | * |
| 1425 | * @hide |
| 1426 | */ |
| 1427 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1428 | |
| 1429 | /** |
| 1430 | * Code used to indicate that device has an account that prevents provisioning. |
| 1431 | * |
| 1432 | * @hide |
| 1433 | */ |
| 1434 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1435 | |
| 1436 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1437 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1438 | * |
| 1439 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1440 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1441 | * |
| 1442 | * @hide |
| 1443 | */ |
| 1444 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1445 | |
| 1446 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1447 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1448 | * |
| 1449 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1450 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1451 | * when the device is a watch and is already paired. |
| 1452 | * |
| 1453 | * @hide |
| 1454 | */ |
| 1455 | public static final int CODE_HAS_PAIRED = 8; |
| 1456 | |
| 1457 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1458 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1459 | * |
| 1460 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1461 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1462 | * |
| 1463 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1464 | * @hide |
| 1465 | */ |
| 1466 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1467 | |
| 1468 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1469 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1470 | * |
| 1471 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1472 | * |
| 1473 | * @hide |
| 1474 | */ |
| 1475 | public static final int CODE_SYSTEM_USER = 10; |
| 1476 | |
| 1477 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1478 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1479 | * |
| 1480 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1481 | * managed profiles. |
| 1482 | * |
| 1483 | * @hide |
| 1484 | */ |
| 1485 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1486 | |
| 1487 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1488 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1489 | * |
| 1490 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1491 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1492 | * user. |
| 1493 | * |
| 1494 | * @hide |
| 1495 | */ |
| 1496 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1497 | |
| 1498 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1499 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1500 | * |
| 1501 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1502 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1503 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1504 | * admins. |
| 1505 | * |
| 1506 | * @hide |
| 1507 | */ |
| 1508 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1509 | |
| 1510 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1511 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1512 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1513 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1514 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1515 | * |
| 1516 | * @hide |
| 1517 | */ |
| 1518 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1519 | |
| 1520 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1521 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1522 | * |
| 1523 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1524 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1525 | * |
| 1526 | * @hide |
| 1527 | */ |
| 1528 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1529 | |
| 1530 | /** |
| 1531 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1532 | * conditions. |
| 1533 | * |
| 1534 | * @hide |
| 1535 | */ |
| 1536 | @Retention(RetentionPolicy.SOURCE) |
| 1537 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1538 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1539 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1540 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1541 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1542 | public @interface ProvisioningPreCondition {} |
| 1543 | |
| 1544 | /** |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 1545 | * Disable all configurable SystemUI features during LockTask mode. This includes, |
| 1546 | * <ul> |
| 1547 | * <li>system info area in the status bar (connectivity icons, clock, etc.) |
| 1548 | * <li>notifications (including alerts, icons, and the notification shade) |
| 1549 | * <li>Home button |
| 1550 | * <li>Recents button and UI |
| 1551 | * <li>global actions menu (i.e. power button menu) |
| 1552 | * <li>keyguard |
| 1553 | * </ul> |
| 1554 | * |
| 1555 | * This is the default configuration for LockTask. |
| 1556 | * |
| 1557 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1558 | */ |
| 1559 | public static final int LOCK_TASK_FEATURE_NONE = 0; |
| 1560 | |
| 1561 | /** |
| 1562 | * Enable the system info area in the status bar during LockTask mode. The system info area |
| 1563 | * usually occupies the right side of the status bar (although this can differ across OEMs). It |
| 1564 | * includes all system information indicators, such as date and time, connectivity, battery, |
| 1565 | * vibration mode, etc. |
| 1566 | * |
| 1567 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1568 | */ |
| 1569 | public static final int LOCK_TASK_FEATURE_SYSTEM_INFO = 1; |
| 1570 | |
| 1571 | /** |
| 1572 | * Enable notifications during LockTask mode. This includes notification icons on the status |
| 1573 | * bar, heads-up notifications, and the expandable notification shade. Note that the Quick |
| 1574 | * Settings panel will still be disabled. |
| 1575 | * |
| 1576 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1577 | */ |
| 1578 | public static final int LOCK_TASK_FEATURE_NOTIFICATIONS = 1 << 1; |
| 1579 | |
| 1580 | /** |
| 1581 | * Enable the Home button during LockTask mode. Note that if a custom launcher is used, it has |
| 1582 | * to be registered as the default launcher with |
| 1583 | * {@link #addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}, and its |
| 1584 | * package needs to be whitelisted for LockTask with |
| 1585 | * {@link #setLockTaskPackages(ComponentName, String[])}. |
| 1586 | * |
| 1587 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1588 | */ |
| 1589 | public static final int LOCK_TASK_FEATURE_HOME = 1 << 2; |
| 1590 | |
| 1591 | /** |
| 1592 | * Enable the Recents button and the Recents screen during LockTask mode. |
| 1593 | * |
| 1594 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1595 | */ |
| 1596 | public static final int LOCK_TASK_FEATURE_RECENTS = 1 << 3; |
| 1597 | |
| 1598 | /** |
| 1599 | * Enable the global actions dialog during LockTask mode. This is the dialog that shows up when |
| 1600 | * the user long-presses the power button, for example. Note that the user may not be able to |
| 1601 | * power off the device if this flag is not set. |
| 1602 | * |
| 1603 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1604 | */ |
| 1605 | public static final int LOCK_TASK_FEATURE_GLOBAL_ACTIONS = 1 << 4; |
| 1606 | |
| 1607 | /** |
| 1608 | * Enable the keyguard during LockTask mode. Note that if the keyguard is already disabled with |
| 1609 | * {@link #setKeyguardDisabled(ComponentName, boolean)}, setting this flag will have no effect. |
| 1610 | * If this flag is not set, the keyguard will not be shown even if the user has a lock screen |
| 1611 | * credential. |
| 1612 | * |
| 1613 | * @see #setLockTaskFeatures(ComponentName, int) |
| 1614 | */ |
| 1615 | public static final int LOCK_TASK_FEATURE_KEYGUARD = 1 << 5; |
| 1616 | |
| 1617 | /** |
| 1618 | * Flags supplied to {@link #setLockTaskFeatures(ComponentName, int)}. |
| 1619 | * |
| 1620 | * @hide |
| 1621 | */ |
| 1622 | @Retention(RetentionPolicy.SOURCE) |
| 1623 | @IntDef(flag = true, |
| 1624 | value = {LOCK_TASK_FEATURE_NONE, LOCK_TASK_FEATURE_SYSTEM_INFO, |
| 1625 | LOCK_TASK_FEATURE_NOTIFICATIONS, LOCK_TASK_FEATURE_HOME, |
| 1626 | LOCK_TASK_FEATURE_RECENTS, LOCK_TASK_FEATURE_GLOBAL_ACTIONS, |
| 1627 | LOCK_TASK_FEATURE_KEYGUARD}) |
| 1628 | public @interface LockTaskFeature {} |
| 1629 | |
| 1630 | /** |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1631 | * Service action: Action for a service that device owner and profile owner can optionally |
| 1632 | * own. If a device owner or a profile owner has such a service, the system tries to keep |
| 1633 | * 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] | 1634 | * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN} |
| 1635 | * permission. |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1636 | */ |
| 1637 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
| 1638 | public static final String ACTION_DEVICE_ADMIN_SERVICE |
| 1639 | = "android.app.action.DEVICE_ADMIN_SERVICE"; |
| 1640 | |
| 1641 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1642 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1643 | * |
| 1644 | * @param admin The administrator component to check for. |
| 1645 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1646 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1647 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1648 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1649 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1650 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | /** |
| 1654 | * @see #isAdminActive(ComponentName) |
| 1655 | * @hide |
| 1656 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1657 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1658 | if (mService != null) { |
| 1659 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1660 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1661 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1662 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | return false; |
| 1666 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1667 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1668 | /** |
| 1669 | * Return true if the given administrator component is currently being removed |
| 1670 | * for the user. |
| 1671 | * @hide |
| 1672 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1673 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1674 | if (mService != null) { |
| 1675 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1676 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1677 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1678 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1684 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1685 | * Return a list of all currently active device administrators' component |
| 1686 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1687 | * returned. |
| 1688 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1689 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1690 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1691 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | /** |
| 1695 | * @see #getActiveAdmins() |
| 1696 | * @hide |
| 1697 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1698 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1699 | if (mService != null) { |
| 1700 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1701 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1702 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1703 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1704 | } |
| 1705 | } |
| 1706 | return null; |
| 1707 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1708 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1709 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1710 | * Used by package administration code to determine if a package can be stopped |
| 1711 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1712 | * @hide |
| 1713 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1714 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 1715 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1716 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1717 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1718 | } |
| 1719 | |
| 1720 | /** |
| 1721 | * Used by package administration code to determine if a package can be stopped |
| 1722 | * or uninstalled. |
| 1723 | * @hide |
| 1724 | */ |
| 1725 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1726 | if (mService != null) { |
| 1727 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1728 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1729 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1730 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | return false; |
| 1734 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1735 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1736 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1737 | * Remove a current administration component. This can only be called |
| 1738 | * by the application that owns the administration component; if you |
| 1739 | * try to remove someone else's component, a security exception will be |
| 1740 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1741 | * |
| 1742 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1743 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1744 | * |
| 1745 | * @param admin The administration compononent to remove. |
| 1746 | * @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] | 1747 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1748 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1749 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1750 | if (mService != null) { |
| 1751 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1752 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1753 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1754 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1755 | } |
| 1756 | } |
| 1757 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1758 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1759 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1760 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1761 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1762 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1763 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1764 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1765 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1766 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1767 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1768 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1769 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1770 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1771 | if (mService != null) { |
| 1772 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1773 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1774 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1775 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | return false; |
| 1779 | } |
| 1780 | |
| 1781 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1782 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1783 | * |
| 1784 | * @hide |
| 1785 | */ |
| 1786 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1787 | if (mService != null) { |
| 1788 | try { |
| 1789 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1790 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1791 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | return false; |
| 1795 | } |
| 1796 | |
| 1797 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1798 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1799 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1800 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1801 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1802 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1803 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1804 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1805 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1806 | * recognition technology. This implies technologies that can recognize the identity of |
| 1807 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1808 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1809 | */ |
| 1810 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1811 | |
| 1812 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1813 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1814 | * 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] | 1815 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1816 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1817 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1818 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1819 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1820 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1821 | * password containing at least numeric characters. Note that quality |
| 1822 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1823 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1824 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1825 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1826 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1827 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1828 | * password containing at least numeric characters with no repeating (4444) |
| 1829 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1830 | * constants are ordered so that higher values are more restrictive. |
| 1831 | */ |
| 1832 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1833 | |
| 1834 | /** |
| 1835 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1836 | * password containing at least alphabetic (or other symbol) characters. |
| 1837 | * Note that quality constants are ordered so that higher values are more |
| 1838 | * restrictive. |
| 1839 | */ |
| 1840 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1841 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1842 | /** |
| 1843 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1844 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1845 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1846 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1847 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1848 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1849 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1850 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1851 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1852 | * password containing at least a letter, a numerical digit and a special |
| 1853 | * symbol, by default. With this password quality, passwords can be |
| 1854 | * restricted to contain various sets of characters, like at least an |
| 1855 | * uppercase letter, etc. These are specified using various methods, |
| 1856 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1857 | * that quality constants are ordered so that higher values are more |
| 1858 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1859 | */ |
| 1860 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1861 | |
| 1862 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1863 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1864 | * modify password. In case this password quality is set, the password is |
| 1865 | * managed by a profile owner. The profile owner can set any password, |
| 1866 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1867 | * that quality constants are ordered so that higher values are more |
| 1868 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1869 | * the highest. |
| 1870 | * @hide |
| 1871 | */ |
| 1872 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1873 | |
| 1874 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1875 | * @hide |
| 1876 | * |
| 1877 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1878 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1879 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1880 | * used by authenticator to exempt their accounts from this: |
| 1881 | * |
| 1882 | * <ul> |
| 1883 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1884 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1885 | * <application> tag in the manifest. |
| 1886 | * |
| 1887 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1888 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1889 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1890 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1891 | * if any of the accounts have it. |
| 1892 | * </ul> |
| 1893 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1894 | @SystemApi |
| 1895 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1896 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1897 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1898 | |
| 1899 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1900 | @SystemApi |
| 1901 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1902 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1903 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1904 | |
| 1905 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1906 | * Called by an application that is administering the device to set the password restrictions it |
| 1907 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1908 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1909 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1910 | * 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] | 1911 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1912 | * <p> |
| 1913 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1914 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1915 | * considerations) is the one that is in effect. |
| 1916 | * <p> |
| 1917 | * The calling device admin must have requested |
| 1918 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1919 | * not, a security exception will be thrown. |
| 1920 | * <p> |
| 1921 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1922 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1923 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1924 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1925 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1926 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1927 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1928 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1929 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1930 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1931 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1932 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1933 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1934 | if (mService != null) { |
| 1935 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1936 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1937 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1938 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1942 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1943 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1944 | * 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] | 1945 | * 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] | 1946 | * a separate challenge are not taken into account. |
| 1947 | * |
| 1948 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1949 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1950 | * restrictions on the parent profile. |
| 1951 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1952 | * @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] | 1953 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1954 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1955 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1956 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1960 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1961 | if (mService != null) { |
| 1962 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1963 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1964 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1965 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1966 | } |
| 1967 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1968 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1969 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1970 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1971 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1972 | * Called by an application that is administering the device to set the minimum allowed password |
| 1973 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1974 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1975 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1976 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1977 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1978 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1979 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1980 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1981 | * {@link #setPasswordQuality}. |
| 1982 | * <p> |
| 1983 | * The calling device admin must have requested |
| 1984 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1985 | * not, a security exception will be thrown. |
| 1986 | * <p> |
| 1987 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1988 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1989 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1990 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1991 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1992 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1993 | * restriction. |
| 1994 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1995 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1996 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1997 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1998 | if (mService != null) { |
| 1999 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2000 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2001 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2002 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2006 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2007 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2008 | * 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] | 2009 | * 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] | 2010 | * a separate challenge are not taken into account. |
| 2011 | * |
| 2012 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2013 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2014 | * restrictions on the parent profile. |
| 2015 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2016 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2017 | * @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] | 2018 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2019 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2020 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2021 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2025 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2026 | if (mService != null) { |
| 2027 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2028 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2029 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2030 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2031 | } |
| 2032 | } |
| 2033 | return 0; |
| 2034 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2035 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2036 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2037 | * Called by an application that is administering the device to set the minimum number of upper |
| 2038 | * case letters required in the password. After setting this, the user will not be able to enter |
| 2039 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 2040 | * current password will remain until the user has set a new one, so the change does not take |
| 2041 | * place immediately. To prompt the user for a new password, use |
| 2042 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2043 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2044 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2045 | * <p> |
| 2046 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2047 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2048 | * not, a security exception will be thrown. |
| 2049 | * <p> |
| 2050 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2051 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2052 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2053 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2054 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2055 | * @param length The new desired minimum number of upper case letters required in the password. |
| 2056 | * A value of 0 means there is no restriction. |
| 2057 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2058 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2059 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2060 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2061 | if (mService != null) { |
| 2062 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2063 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2064 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2065 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2071 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2072 | * 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] | 2073 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 2074 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2075 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2076 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2077 | * and only applies when the password quality is |
| 2078 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2079 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2080 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2081 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2082 | * restrictions on the parent profile. |
| 2083 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2084 | * @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] | 2085 | * aggregate all admins. |
| 2086 | * @return The minimum number of upper case letters required in the |
| 2087 | * password. |
| 2088 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2089 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2090 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2094 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2095 | if (mService != null) { |
| 2096 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2097 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2098 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2099 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2106 | * Called by an application that is administering the device to set the minimum number of lower |
| 2107 | * case letters required in the password. After setting this, the user will not be able to enter |
| 2108 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 2109 | * current password will remain until the user has set a new one, so the change does not take |
| 2110 | * place immediately. To prompt the user for a new password, use |
| 2111 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2112 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2113 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2114 | * <p> |
| 2115 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2116 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2117 | * not, a security exception will be thrown. |
| 2118 | * <p> |
| 2119 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2120 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2121 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2122 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2123 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2124 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2125 | * A value of 0 means there is no restriction. |
| 2126 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2127 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2128 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2129 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2130 | if (mService != null) { |
| 2131 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2132 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2133 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2134 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2135 | } |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2140 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2141 | * 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] | 2142 | * and its participating profiles. Restrictions on profiles that have |
| 2143 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2144 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2145 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2146 | * and only applies when the password quality is |
| 2147 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2148 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2149 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2150 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2151 | * restrictions on the parent profile. |
| 2152 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2153 | * @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] | 2154 | * aggregate all admins. |
| 2155 | * @return The minimum number of lower case letters required in the |
| 2156 | * password. |
| 2157 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2158 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2159 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2163 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2164 | if (mService != null) { |
| 2165 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2166 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2167 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2168 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2169 | } |
| 2170 | } |
| 2171 | return 0; |
| 2172 | } |
| 2173 | |
| 2174 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2175 | * Called by an application that is administering the device to set the minimum number of |
| 2176 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2177 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2178 | * password will remain until the user has set a new one, so the change does not take place |
| 2179 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2180 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2181 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2182 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2183 | * <p> |
| 2184 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2185 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2186 | * not, a security exception will be thrown. |
| 2187 | * <p> |
| 2188 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2189 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2190 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2191 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2192 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2193 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2194 | * 0 means there is no restriction. |
| 2195 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2196 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2197 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2198 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2199 | if (mService != null) { |
| 2200 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2201 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2202 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2203 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2209 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2210 | * 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] | 2211 | * and its participating profiles. Restrictions on profiles that have |
| 2212 | * a separate challenge are not taken into account. |
| 2213 | * This is the same value as set by |
| 2214 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2215 | * and only applies when the password quality is |
| 2216 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2217 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2218 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2219 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2220 | * restrictions on the parent profile. |
| 2221 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2222 | * @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] | 2223 | * aggregate all admins. |
| 2224 | * @return The minimum number of letters required in the password. |
| 2225 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2226 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2227 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2231 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
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 | return mService.getPasswordMinimumLetters(admin, userHandle, 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 | return 0; |
| 2240 | } |
| 2241 | |
| 2242 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2243 | * Called by an application that is administering the device to set the minimum number of |
| 2244 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2245 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2246 | * current password will remain until the user has set a new one, so the change does not take |
| 2247 | * place immediately. To prompt the user for a new password, use |
| 2248 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2249 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2250 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2251 | * <p> |
| 2252 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2253 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2254 | * not, a security exception will be thrown. |
| 2255 | * <p> |
| 2256 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2257 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2258 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2259 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2260 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2261 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2262 | * value of 0 means there is no restriction. |
| 2263 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2264 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2265 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2266 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
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 | mService.setPasswordMinimumNumeric(admin, length, 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 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2278 | * 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] | 2279 | * and its participating profiles. Restrictions on profiles that have |
| 2280 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2281 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2282 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2283 | * and only applies when the password quality is |
| 2284 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2285 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2286 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2287 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2288 | * restrictions on the parent profile. |
| 2289 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2290 | * @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] | 2291 | * aggregate all admins. |
| 2292 | * @return The minimum number of numerical digits required in the password. |
| 2293 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2294 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2295 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2299 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2300 | if (mService != null) { |
| 2301 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2302 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2303 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2304 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2305 | } |
| 2306 | } |
| 2307 | return 0; |
| 2308 | } |
| 2309 | |
| 2310 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2311 | * Called by an application that is administering the device to set the minimum number of |
| 2312 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2313 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2314 | * password will remain until the user has set a new one, so the change does not take place |
| 2315 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2316 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2317 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2318 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2319 | * <p> |
| 2320 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2321 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2322 | * not, a security exception will be thrown. |
| 2323 | * <p> |
| 2324 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2325 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2326 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2327 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2328 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2329 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2330 | * 0 means there is no restriction. |
| 2331 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2332 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2333 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2334 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2335 | if (mService != null) { |
| 2336 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2337 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2338 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2339 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2340 | } |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2345 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2346 | * 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] | 2347 | * and its participating profiles. Restrictions on profiles that have |
| 2348 | * a separate challenge are not taken into account. This is the same value as |
| 2349 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2350 | * and only applies when the password quality is |
| 2351 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2352 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2353 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2354 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2355 | * restrictions on the parent profile. |
| 2356 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2357 | * @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] | 2358 | * aggregate all admins. |
| 2359 | * @return The minimum number of symbols required in the password. |
| 2360 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2361 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2362 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2366 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2367 | if (mService != null) { |
| 2368 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2369 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2370 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2371 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | return 0; |
| 2375 | } |
| 2376 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2377 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2378 | * Called by an application that is administering the device to set the minimum number of |
| 2379 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2380 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2381 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2382 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2383 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2384 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2385 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2386 | * <p> |
| 2387 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2388 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2389 | * not, a security exception will be thrown. |
| 2390 | * <p> |
| 2391 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2392 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2393 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2394 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2395 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2396 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2397 | * 0 means there is no restriction. |
| 2398 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2399 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2400 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2401 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2402 | if (mService != null) { |
| 2403 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2404 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2405 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2406 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2412 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2413 | * 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] | 2414 | * and its participating profiles. Restrictions on profiles that have |
| 2415 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2416 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2417 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2418 | * and only applies when the password quality is |
| 2419 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2420 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2421 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2422 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2423 | * restrictions on the parent profile. |
| 2424 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2425 | * @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] | 2426 | * aggregate all admins. |
| 2427 | * @return The minimum number of letters required in the password. |
| 2428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2429 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2430 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2434 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2435 | if (mService != null) { |
| 2436 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2437 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2438 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2439 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2440 | } |
| 2441 | } |
| 2442 | return 0; |
| 2443 | } |
| 2444 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2445 | /** |
| 2446 | * Called by an application that is administering the device to set the length of the password |
| 2447 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2448 | * same as any password in the history. Note that the current password will remain until the |
| 2449 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2450 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2451 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2452 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2453 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2454 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2455 | * <p> |
| 2456 | * The calling device admin must have requested |
| 2457 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2458 | * not, a security exception will be thrown. |
| 2459 | * <p> |
| 2460 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2461 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2462 | * profile. |
| 2463 | * |
| 2464 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2465 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2466 | * restriction. |
| 2467 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2468 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2469 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2470 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2471 | if (mService != null) { |
| 2472 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2473 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2474 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2475 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2481 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2482 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2483 | * device password (for all admins). |
| 2484 | * <p> |
| 2485 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2486 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2487 | * 432000000 ms for timeout. |
| 2488 | * <p> |
| 2489 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2490 | * <p> |
| 2491 | * The calling device admin must have requested |
| 2492 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2493 | * not, a security exception will be thrown. |
| 2494 | * <p> |
| 2495 | * Note that setting the password will automatically reset the expiration time for all active |
| 2496 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2497 | * <p> |
| 2498 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2499 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2500 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2501 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2502 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2503 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2504 | * there is no restriction (unlimited). |
| 2505 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2506 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2507 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2508 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2509 | if (mService != null) { |
| 2510 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2511 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2512 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2513 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2514 | } |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2519 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2520 | * recurring expiration timeout provided in the call to |
| 2521 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2522 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2523 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2524 | * |
| 2525 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2526 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2527 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2528 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2529 | * @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] | 2530 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2531 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2532 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2533 | if (mService != null) { |
| 2534 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2535 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2536 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2537 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | return 0; |
| 2541 | } |
| 2542 | |
| 2543 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2544 | * 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] | 2545 | * 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] | 2546 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2547 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2548 | * |
| 2549 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2550 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2551 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2552 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2553 | * @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] | 2554 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2555 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2556 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2557 | if (mService != null) { |
| 2558 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2559 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2560 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2561 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | return 0; |
| 2565 | } |
| 2566 | |
| 2567 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2568 | * 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] | 2569 | * 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] | 2570 | * have a separate challenge are not taken into account. |
| 2571 | * |
| 2572 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2573 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2574 | * restrictions on the parent profile. |
| 2575 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2576 | * @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] | 2577 | * all admins. |
| 2578 | * @return The length of the password history |
| 2579 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2580 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2581 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2585 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2586 | if (mService != null) { |
| 2587 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2588 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2589 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2590 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | return 0; |
| 2594 | } |
| 2595 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2596 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2597 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2598 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2599 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2600 | * @return Returns the maximum length that the user can enter. |
| 2601 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2602 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2603 | // Kind-of arbitrary. |
| 2604 | return 16; |
| 2605 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2606 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2607 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2608 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2609 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2610 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2611 | * 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] | 2612 | * <p> |
| 2613 | * The calling device admin must have requested |
| 2614 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2615 | * not, a security exception will be thrown. |
| 2616 | * <p> |
| 2617 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2618 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2619 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2620 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2621 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2622 | * @throws SecurityException if the calling application does not own an active administrator |
| 2623 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Rubin Xu | 7cf4509 | 2017-08-28 11:47:35 +0100 | [diff] [blame] | 2624 | * @throws IllegalStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2625 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2626 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2627 | if (mService != null) { |
| 2628 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2629 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2630 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2631 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2632 | } |
| 2633 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2634 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2635 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2636 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2637 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2638 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2639 | * 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] | 2640 | * requested by the admins of the parent user and its profiles. |
| 2641 | * |
| 2642 | * @param userHandle the userId of the profile to check the password for. |
| 2643 | * @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] | 2644 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2645 | * @hide |
| 2646 | */ |
| 2647 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2648 | if (mService != null) { |
| 2649 | try { |
| 2650 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2651 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2652 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | return false; |
| 2656 | } |
| 2657 | |
| 2658 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2659 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2660 | * successful password entry. |
| 2661 | * <p> |
| 2662 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2663 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2664 | * password attemts for the parent user. |
| 2665 | * <p> |
| 2666 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2667 | * 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] | 2668 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2669 | * @return The number of times user has entered an incorrect password since the last correct |
| 2670 | * password entry. |
| 2671 | * @throws SecurityException if the calling application does not own an active administrator |
| 2672 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2673 | */ |
| 2674 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2675 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2676 | } |
| 2677 | |
| 2678 | /** |
| 2679 | * Retrieve the number of times the given user has failed at entering a |
| 2680 | * password since that last successful password entry. |
| 2681 | * |
| 2682 | * <p>The calling device admin must have requested |
| 2683 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2684 | * not and it is not the system uid, a security exception will be thrown. |
| 2685 | * |
| 2686 | * @hide |
| 2687 | */ |
| 2688 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2689 | if (mService != null) { |
| 2690 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2691 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2692 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2693 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | return -1; |
| 2697 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2698 | |
| 2699 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2700 | * 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] | 2701 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2702 | * @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] | 2703 | * @hide |
| 2704 | */ |
| 2705 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2706 | if (mService != null) { |
| 2707 | try { |
| 2708 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2709 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2710 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | return false; |
| 2714 | } |
| 2715 | |
| 2716 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2717 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2718 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2719 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2720 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2721 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2722 | * <p> |
| 2723 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2724 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2725 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2726 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2727 | * immediately, and your callback will not be invoked. |
| 2728 | * <p> |
| 2729 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2730 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2731 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2732 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2733 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2734 | * @param num The number of failed password attempts at which point the device or profile will |
| 2735 | * be wiped. |
| 2736 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2737 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2738 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2739 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2740 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2741 | if (mService != null) { |
| 2742 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2743 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2744 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2745 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2746 | } |
| 2747 | } |
| 2748 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2749 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2750 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2751 | * 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] | 2752 | * 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] | 2753 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2754 | * not taken into account. |
| 2755 | * |
| 2756 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2757 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2758 | * the value for the parent profile. |
| 2759 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2760 | * @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] | 2761 | * all admins. |
| 2762 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2763 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2764 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2768 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2769 | if (mService != null) { |
| 2770 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2771 | return mService.getMaximumFailedPasswordsForWipe( |
| 2772 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2773 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2774 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | return 0; |
| 2778 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2779 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2780 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2781 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2782 | * for the given user. So for primary user, it might return the primary or |
| 2783 | * a managed profile. For a secondary user, it would be the same as the |
| 2784 | * user passed in. |
| 2785 | * @hide Used only by Keyguard |
| 2786 | */ |
| 2787 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2788 | if (mService != null) { |
| 2789 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2790 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2791 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2792 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2793 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | return UserHandle.USER_NULL; |
| 2797 | } |
| 2798 | |
| 2799 | /** |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2800 | * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't allow other admins |
| 2801 | * to change the password again until the user has entered it. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2802 | */ |
| 2803 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2804 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2805 | /** |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2806 | * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't ask for user |
| 2807 | * credentials on device boot. |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2808 | * If the flag is set, the device can be booted without asking for user password. |
| 2809 | * The absence of this flag does not change the current boot requirements. This flag |
| 2810 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2811 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2812 | * device to factory defaults. |
| 2813 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2814 | 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] | 2815 | |
| 2816 | /** |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2817 | * Force a new password for device unlock (the password needed to access the entire device) or |
| 2818 | * the work profile challenge on the current user. This takes effect immediately. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2819 | * <p> |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2820 | * <em>For device owner and profile owners targeting SDK level |
| 2821 | * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will |
| 2822 | * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken} |
| 2823 | * instead. </em> |
| 2824 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2825 | * <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] | 2826 | * device admins that are not device owner and not profile owner. |
| 2827 | * 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] | 2828 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2829 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2830 | * <p> |
| 2831 | * The given password must be sufficient for the current password quality and length constraints |
| 2832 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2833 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2834 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2835 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2836 | * case the currently active quality will be increased to match. |
| 2837 | * <p> |
| 2838 | * 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] | 2839 | * current password constraints allow it. <em>Note: This will not work in |
| 2840 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2841 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2842 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2843 | * <p> |
| 2844 | * The calling device admin must have requested |
| 2845 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2846 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2847 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2848 | * @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] | 2849 | * @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] | 2850 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2851 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2852 | * current constraints or if the user has not been decrypted yet. |
| 2853 | * @throws SecurityException if the calling application does not own an active administrator |
| 2854 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2855 | * @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] | 2856 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2857 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2858 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2859 | if (mService != null) { |
| 2860 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2861 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2862 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2863 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | return false; |
| 2867 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2868 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2869 | /** |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2870 | * 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] | 2871 | * device lockscreen password (if called by device owner), or managed profile challenge (if |
| 2872 | * called by profile owner), via {@link #resetPasswordWithToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2873 | * <p> |
| 2874 | * If the user currently has a lockscreen password, the provisioned token will not be |
| 2875 | * immediately usable; it only becomes active after the user performs a confirm credential |
| 2876 | * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 2877 | * If the user has no lockscreen password, the token is activated immediately. In all cases, |
| 2878 | * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}. |
| 2879 | * For security reasons, un-activated tokens are only stored in memory and will be lost once |
| 2880 | * the device reboots. In this case a new token needs to be provisioned again. |
| 2881 | * <p> |
| 2882 | * Once provisioned and activated, the token will remain effective even if the user changes |
| 2883 | * or clears the lockscreen password. |
| 2884 | * <p> |
| 2885 | * <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] | 2886 | * credentials. In particular, NEVER store this token on device in plaintext. Do not store |
| 2887 | * the plaintext token in device-encrypted storage if it will be needed to reset password on |
| 2888 | * file-based encryption devices before user unlocks. Consider carefully how any password token |
| 2889 | * will be stored on your server and who will need access to them. Tokens may be the subject of |
| 2890 | * legal access requests. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2891 | * </em> |
| 2892 | * |
| 2893 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2894 | * @param token a secure token a least 32-byte long, which must be generated by a |
| 2895 | * cryptographically strong random number generator. |
| 2896 | * @return true if the operation is successful, false otherwise. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2897 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2898 | * @throws IllegalArgumentException if the supplied token is invalid. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2899 | */ |
| 2900 | public boolean setResetPasswordToken(ComponentName admin, byte[] token) { |
| 2901 | throwIfParentInstance("setResetPasswordToken"); |
| 2902 | if (mService != null) { |
| 2903 | try { |
| 2904 | return mService.setResetPasswordToken(admin, token); |
| 2905 | } catch (RemoteException e) { |
| 2906 | throw e.rethrowFromSystemServer(); |
| 2907 | } |
| 2908 | } |
| 2909 | return false; |
| 2910 | } |
| 2911 | |
| 2912 | /** |
| 2913 | * Called by a profile or device owner to revoke the current password reset token. |
| 2914 | * |
| 2915 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2916 | * @return true if the operation is successful, false otherwise. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2917 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2918 | */ |
| 2919 | public boolean clearResetPasswordToken(ComponentName admin) { |
| 2920 | throwIfParentInstance("clearResetPasswordToken"); |
| 2921 | if (mService != null) { |
| 2922 | try { |
| 2923 | return mService.clearResetPasswordToken(admin); |
| 2924 | } catch (RemoteException e) { |
| 2925 | throw e.rethrowFromSystemServer(); |
| 2926 | } |
| 2927 | } |
| 2928 | return false; |
| 2929 | } |
| 2930 | |
| 2931 | /** |
| 2932 | * Called by a profile or device owner to check if the current reset password token is active. |
| 2933 | * |
| 2934 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2935 | * @return true if the token is active, false otherwise. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2936 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2937 | * @throws IllegalStateException if no token has been set. |
| 2938 | */ |
| 2939 | public boolean isResetPasswordTokenActive(ComponentName admin) { |
| 2940 | throwIfParentInstance("isResetPasswordTokenActive"); |
| 2941 | if (mService != null) { |
| 2942 | try { |
| 2943 | return mService.isResetPasswordTokenActive(admin); |
| 2944 | } catch (RemoteException e) { |
| 2945 | throw e.rethrowFromSystemServer(); |
| 2946 | } |
| 2947 | } |
| 2948 | return false; |
| 2949 | } |
| 2950 | |
| 2951 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2952 | * Called by device or profile owner to force set a new device unlock password or a managed |
| 2953 | * profile challenge on current user. This takes effect immediately. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2954 | * <p> |
| 2955 | * Unlike {@link #resetPassword}, this API can change the password even before the user or |
| 2956 | * device is unlocked or decrypted. The supplied token must have been previously provisioned via |
| 2957 | * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}. |
| 2958 | * <p> |
| 2959 | * The given password must be sufficient for the current password quality and length constraints |
| 2960 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2961 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2962 | * it will be rejected and false returned. Note that the password may be a stronger quality, for |
| 2963 | * example, a password containing alphanumeric characters when the requested quality is only |
| 2964 | * numeric. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2965 | * <p> |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2966 | * Calling with a {@code null} or empty password will clear any existing PIN, pattern or |
| 2967 | * password if the current password constraints allow it. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2968 | * |
| 2969 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2970 | * @param password The new password for the user. {@code null} or empty clears the password. |
| 2971 | * @param token the password reset token previously provisioned by |
| 2972 | * {@link #setResetPasswordToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2973 | * @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] | 2974 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2975 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2976 | * current constraints. |
Benjamin Miller | 1aed788 | 2017-08-15 18:04:20 +0200 | [diff] [blame] | 2977 | * @throws SecurityException if admin is not a device or profile owner. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2978 | * @throws IllegalStateException if the provided token is not valid. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2979 | */ |
| 2980 | public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password, |
| 2981 | byte[] token, int flags) { |
| 2982 | throwIfParentInstance("resetPassword"); |
| 2983 | if (mService != null) { |
| 2984 | try { |
| 2985 | return mService.resetPasswordWithToken(admin, password, token, flags); |
| 2986 | } catch (RemoteException e) { |
| 2987 | throw e.rethrowFromSystemServer(); |
| 2988 | } |
| 2989 | } |
| 2990 | return false; |
| 2991 | } |
| 2992 | |
| 2993 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2994 | * Called by an application that is administering the device to set the maximum time for user |
| 2995 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2996 | * effect immediately. |
| 2997 | * <p> |
| 2998 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2999 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3000 | * <p> |
| 3001 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3002 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3003 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3004 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 3005 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3006 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 3007 | * is no restriction. |
| 3008 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 3009 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3010 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3011 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3012 | if (mService != null) { |
| 3013 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3014 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3015 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3016 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3020 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3021 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3022 | * 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] | 3023 | * 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] | 3024 | * a separate challenge are not taken into account. |
| 3025 | * |
| 3026 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3027 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3028 | * restrictions on the parent profile. |
| 3029 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3030 | * @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] | 3031 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 3032 | * @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] | 3033 | * 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] | 3034 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3035 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3036 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3040 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3041 | if (mService != null) { |
| 3042 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3043 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3044 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3045 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | return 0; |
| 3049 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3050 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3051 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 3052 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 3053 | * do not have a separate timeout to lock for work challenge only. |
| 3054 | * |
| 3055 | * @hide |
| 3056 | */ |
| 3057 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 3058 | if (mService != null) { |
| 3059 | try { |
| 3060 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 3061 | } catch (RemoteException e) { |
| 3062 | throw e.rethrowFromSystemServer(); |
| 3063 | } |
| 3064 | } |
| 3065 | return 0; |
| 3066 | } |
| 3067 | |
| 3068 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3069 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 3070 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 3071 | * authentication method like password, pin or pattern. |
| 3072 | * |
| 3073 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 3074 | * specified timeout each time it has been successfully used. |
| 3075 | * |
| 3076 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 3077 | * |
| 3078 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 3079 | * |
| 3080 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 3081 | * a {@link SecurityException} will be thrown. |
| 3082 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 3083 | * <p>The calling device admin can verify the value it has set by calling |
| 3084 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 3085 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3086 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3087 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3088 | * profile. |
| 3089 | * |
| 3090 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3091 | * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock |
| 3092 | * with strong authentication method. A value of 0 means the admin is not participating |
| 3093 | * in controlling the timeout. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 3094 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 3095 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 3096 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 3097 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3098 | * |
| 3099 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3100 | */ |
| 3101 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 3102 | long timeoutMs) { |
| 3103 | if (mService != null) { |
| 3104 | try { |
| 3105 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 3106 | } catch (RemoteException e) { |
| 3107 | throw e.rethrowFromSystemServer(); |
| 3108 | } |
| 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | /** |
| 3113 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 3114 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 3115 | * After the returned timeout the user is required to use strong authentication method. |
| 3116 | * |
| 3117 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3118 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3119 | * restrictions on the parent profile. |
| 3120 | * |
| 3121 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 3122 | * accross all participating admins. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3123 | * @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] | 3124 | */ |
| 3125 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 3126 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 3127 | } |
| 3128 | |
| 3129 | /** @hide per-user version */ |
| 3130 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 3131 | if (mService != null) { |
| 3132 | try { |
| 3133 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 3134 | } catch (RemoteException e) { |
| 3135 | throw e.rethrowFromSystemServer(); |
| 3136 | } |
| 3137 | } |
| 3138 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 3139 | } |
| 3140 | |
| 3141 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3142 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 3143 | * keyring. The user's credential will need to be entered again in order to derive the |
| 3144 | * credential encryption key that will be stored back in the keyring for future use. |
| 3145 | * <p> |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3146 | * This flag can only be used by a profile owner when locking a managed profile when |
| 3147 | * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3148 | * <p> |
| 3149 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 3150 | * until they are next run to perform further actions. |
| 3151 | */ |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3152 | public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1; |
| 3153 | |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3154 | /** @hide */ |
| 3155 | @Retention(RetentionPolicy.SOURCE) |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3156 | @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}) |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3157 | public @interface LockNowFlag {} |
| 3158 | |
| 3159 | /** |
| 3160 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3161 | * this call. |
| 3162 | * <p> |
| 3163 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3164 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3165 | * <p> |
| 3166 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3167 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 3168 | * <p> |
| 3169 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 3170 | * |
| 3171 | * @throws SecurityException if the calling application does not own an active administrator |
| 3172 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3173 | */ |
| 3174 | public void lockNow() { |
| 3175 | lockNow(0); |
| 3176 | } |
| 3177 | |
| 3178 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3179 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3180 | * this call. |
| 3181 | * <p> |
| 3182 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3183 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3184 | * <p> |
| 3185 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3186 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3187 | * |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3188 | * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3189 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3190 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3191 | * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application |
| 3192 | * that is not a profile |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3193 | * owner of a managed profile. |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3194 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is |
| 3195 | * passed when locking the parent profile. |
| 3196 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} |
| 3197 | * flag is passed when {@link #getStorageEncryptionStatus} does not return |
| 3198 | * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3199 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3200 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3201 | if (mService != null) { |
| 3202 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3203 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3204 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3205 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3206 | } |
| 3207 | } |
| 3208 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3209 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3210 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3211 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3212 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3213 | */ |
| 3214 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 3215 | |
| 3216 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3217 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 3218 | * data. |
| 3219 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 3220 | * <p>This flag may only be set by device owner admins; if it is set by |
| 3221 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3222 | */ |
| 3223 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 3224 | |
| 3225 | /** |
yinxu | f4f9cec | 2017-06-19 10:28:19 -0700 | [diff] [blame] | 3226 | * Flag for {@link #wipeData(int)}: also erase the device's eUICC data. |
| 3227 | * |
| 3228 | * TODO(b/35851809): make this public. |
| 3229 | * @hide |
| 3230 | */ |
| 3231 | public static final int WIPE_EUICC = 0x0004; |
| 3232 | |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3233 | |
yinxu | f4f9cec | 2017-06-19 10:28:19 -0700 | [diff] [blame] | 3234 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 3235 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3236 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 3237 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 3238 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3239 | * <p> |
| 3240 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3241 | * 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] | 3242 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3243 | * @param flags Bit mask of additional options: currently supported flags are |
| 3244 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3245 | * @throws SecurityException if the calling application does not own an active administrator |
| 3246 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3247 | */ |
| 3248 | public void wipeData(int flags) { |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3249 | final String wipeReasonForUser = mContext.getString( |
| 3250 | R.string.work_profile_deleted_description_dpm_wipe); |
| 3251 | wipeDataInternal(flags, wipeReasonForUser); |
| 3252 | } |
| 3253 | |
| 3254 | /** |
| 3255 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3256 | * other users will remain unaffected, the provided reason for wiping data can be shown to |
| 3257 | * user. Calling from the primary user will cause the device to reboot, erasing all device data |
| 3258 | * - including all the secondary users and their data - while booting up. In this case, we don't |
| 3259 | * show the reason to the user since the device would be factory reset. |
| 3260 | * <p> |
| 3261 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3262 | * be able to call this method; if it has not, a security exception will be thrown. |
| 3263 | * |
| 3264 | * @param flags Bit mask of additional options: currently supported flags are |
| 3265 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3266 | * @param reason a string that contains the reason for wiping data, which can be |
| 3267 | * presented to the user. |
| 3268 | * @throws SecurityException if the calling application does not own an active administrator |
| 3269 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
| 3270 | * @throws IllegalArgumentException if the input reason string is null or empty. |
| 3271 | */ |
| 3272 | public void wipeDataWithReason(int flags, @NonNull CharSequence reason) { |
| 3273 | Preconditions.checkNotNull(reason, "CharSequence is null"); |
| 3274 | wipeDataInternal(flags, reason.toString()); |
| 3275 | } |
| 3276 | |
| 3277 | /** |
| 3278 | * Internal function for both {@link #wipeData(int)} and |
| 3279 | * {@link #wipeDataWithReason(int, CharSequence)} to call. |
| 3280 | * |
| 3281 | * @see #wipeData(int) |
| 3282 | * @see #wipeDataWithReason(int, CharSequence) |
| 3283 | * @hide |
| 3284 | */ |
| 3285 | private void wipeDataInternal(int flags, @NonNull String wipeReasonForUser) { |
| 3286 | throwIfParentInstance("wipeDataWithReason"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3287 | if (mService != null) { |
| 3288 | try { |
yuemingw | f7f67dc | 2017-09-08 14:23:53 +0100 | [diff] [blame] | 3289 | mService.wipeDataWithReason(flags, wipeReasonForUser); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3290 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3291 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3295 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3296 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3297 | * Called by an application that is administering the device to set the |
| 3298 | * global proxy and exclusion list. |
| 3299 | * <p> |
| 3300 | * The calling device admin must have requested |
| 3301 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3302 | * this method; if it has not, a security exception will be thrown. |
| 3303 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3304 | * 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] | 3305 | * 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] | 3306 | * be returned. |
| 3307 | * The method can be called repeatedly by the device admin alrady setting the |
| 3308 | * proxy to update the proxy and exclusion list. |
| 3309 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3310 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3311 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3312 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3313 | * @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] | 3314 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3315 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3316 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3317 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3318 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3319 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3320 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3321 | if (proxySpec == null) { |
| 3322 | throw new NullPointerException(); |
| 3323 | } |
| 3324 | if (mService != null) { |
| 3325 | try { |
| 3326 | String hostSpec; |
| 3327 | String exclSpec; |
| 3328 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3329 | hostSpec = null; |
| 3330 | exclSpec = null; |
| 3331 | } else { |
| 3332 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3333 | throw new IllegalArgumentException(); |
| 3334 | } |
| 3335 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3336 | String hostName = sa.getHostName(); |
| 3337 | int port = sa.getPort(); |
| 3338 | StringBuilder hostBuilder = new StringBuilder(); |
| 3339 | hostSpec = hostBuilder.append(hostName) |
| 3340 | .append(":").append(Integer.toString(port)).toString(); |
| 3341 | if (exclusionList == null) { |
| 3342 | exclSpec = ""; |
| 3343 | } else { |
| 3344 | StringBuilder listBuilder = new StringBuilder(); |
| 3345 | boolean firstDomain = true; |
| 3346 | for (String exclDomain : exclusionList) { |
| 3347 | if (!firstDomain) { |
| 3348 | listBuilder = listBuilder.append(","); |
| 3349 | } else { |
| 3350 | firstDomain = false; |
| 3351 | } |
| 3352 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3353 | } |
| 3354 | exclSpec = listBuilder.toString(); |
| 3355 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3356 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3357 | != android.net.Proxy.PROXY_VALID) |
| 3358 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3359 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3360 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3361 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3362 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | return null; |
| 3366 | } |
| 3367 | |
| 3368 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3369 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3370 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3371 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3372 | * proxy is not accessible, you may break HTTP using this. |
| 3373 | * <p> |
| 3374 | * This method requires the caller to be the device owner. |
| 3375 | * <p> |
| 3376 | * 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] | 3377 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3378 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3379 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3380 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3381 | * {@code null} value will clear the global HTTP proxy. |
| 3382 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3383 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3384 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3385 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3386 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3387 | if (mService != null) { |
| 3388 | try { |
| 3389 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3390 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3391 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3392 | } |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3397 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3398 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3399 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3400 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3401 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3402 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3403 | if (mService != null) { |
| 3404 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3405 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3406 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3407 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3408 | } |
| 3409 | } |
| 3410 | return null; |
| 3411 | } |
| 3412 | |
| 3413 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3414 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3415 | * indicating that encryption is not supported. |
| 3416 | */ |
| 3417 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3418 | |
| 3419 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3420 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3421 | * indicating that encryption is supported, but is not currently active. |
| 3422 | */ |
| 3423 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3424 | |
| 3425 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3426 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3427 | * indicating that encryption is not currently active, but is currently |
| 3428 | * being activated. This is only reported by devices that support |
| 3429 | * encryption of data and only when the storage is currently |
| 3430 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3431 | * to become encrypted will never return this value. |
| 3432 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3433 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3434 | |
| 3435 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3436 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3437 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3438 | * <p> |
| 3439 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3440 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3441 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3442 | |
| 3443 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3444 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3445 | * indicating that encryption is active, but an encryption key has not |
| 3446 | * been set by the user. |
| 3447 | */ |
| 3448 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3449 | |
| 3450 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3451 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3452 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3453 | * <p> |
| 3454 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3455 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3456 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3457 | */ |
| 3458 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3459 | |
| 3460 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3461 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3462 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3463 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3464 | * to check encryption status. However, on some devices this activity may never return, as |
| 3465 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3466 | */ |
| 3467 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3468 | public static final String ACTION_START_ENCRYPTION |
| 3469 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3470 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3471 | * Widgets are enabled in keyguard |
| 3472 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3473 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3474 | |
| 3475 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3476 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3477 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3478 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3479 | |
| 3480 | /** |
| 3481 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3482 | */ |
| 3483 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3484 | |
| 3485 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3486 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3487 | */ |
| 3488 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3489 | |
| 3490 | /** |
| 3491 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3492 | */ |
| 3493 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3494 | |
| 3495 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3496 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3497 | * (e.g. PIN/Pattern/Password). |
| 3498 | */ |
| 3499 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3500 | |
| 3501 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3502 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3503 | */ |
| 3504 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3505 | |
| 3506 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3507 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3508 | */ |
| 3509 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3510 | |
| 3511 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3512 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3513 | */ |
| 3514 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3515 | |
| 3516 | /** |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3517 | * Keyguard features that when set on a managed profile that doesn't have its own challenge will |
| 3518 | * affect the profile's parent user. These can also be set on the managed profile's parent |
| 3519 | * {@link DevicePolicyManager} instance. |
| 3520 | * |
| 3521 | * @hide |
| 3522 | */ |
| 3523 | public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER = |
| 3524 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS |
| 3525 | | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT; |
| 3526 | |
| 3527 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3528 | * Called by an application that is administering the device to request that the storage system |
| 3529 | * be encrypted. |
| 3530 | * <p> |
| 3531 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3532 | * supported setting will always be used. If any device administrator requests device |
| 3533 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3534 | * 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] | 3535 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3536 | * <p> |
| 3537 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3538 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3539 | * control the encryption of any other storage areas. There is one exception: If |
| 3540 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3541 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3542 | * written to disk within the encrypted storage area. |
| 3543 | * <p> |
| 3544 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3545 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3546 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3547 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3548 | * |
| 3549 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3550 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3551 | * @return the new request status (for all active admins) - will be one of |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3552 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3553 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3554 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3555 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3556 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3557 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3558 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3559 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3560 | if (mService != null) { |
| 3561 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3562 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3563 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3564 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3565 | } |
| 3566 | } |
| 3567 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3568 | } |
| 3569 | |
| 3570 | /** |
| 3571 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3572 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3573 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3574 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3575 | * this will return the requested encryption setting as an aggregate of all active |
| 3576 | * administrators. |
| 3577 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3578 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3579 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3580 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3581 | if (mService != null) { |
| 3582 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3583 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3584 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3585 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3586 | } |
| 3587 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3588 | return false; |
| 3589 | } |
| 3590 | |
| 3591 | /** |
| 3592 | * Called by an application that is administering the device to |
| 3593 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3594 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3595 | * Depending on the returned status code, the caller may proceed in different |
| 3596 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3597 | * storage system does not support encryption. If the |
| 3598 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3599 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3600 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3601 | * 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] | 3602 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3603 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3604 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3605 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3606 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3607 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3608 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3609 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3610 | */ |
| 3611 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3612 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3613 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | /** @hide per-user version */ |
| 3617 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3618 | if (mService != null) { |
| 3619 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3620 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3621 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3622 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3623 | } |
| 3624 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3625 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3626 | } |
| 3627 | |
| 3628 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3629 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3630 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3631 | * keep the certificate on the device. |
| 3632 | * |
| 3633 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3634 | * this certificate. |
| 3635 | * |
| 3636 | * @hide |
| 3637 | */ |
| 3638 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3639 | if (mService != null) { |
| 3640 | try { |
| 3641 | return mService.approveCaCert(alias, userHandle, approval); |
| 3642 | } catch (RemoteException e) { |
| 3643 | throw e.rethrowFromSystemServer(); |
| 3644 | } |
| 3645 | } |
| 3646 | return false; |
| 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Check whether a CA certificate has been approved by the device user. |
| 3651 | * |
| 3652 | * @hide |
| 3653 | */ |
| 3654 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3655 | if (mService != null) { |
| 3656 | try { |
| 3657 | return mService.isCaCertApproved(alias, userHandle); |
| 3658 | } catch (RemoteException e) { |
| 3659 | throw e.rethrowFromSystemServer(); |
| 3660 | } |
| 3661 | } |
| 3662 | return false; |
| 3663 | } |
| 3664 | |
| 3665 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3666 | * Installs the given certificate as a user CA. |
| 3667 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3668 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3669 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3670 | * security exception will be thrown. |
| 3671 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3672 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3673 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3674 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3675 | * |
| 3676 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3677 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3678 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3679 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3680 | * @see #setDelegatedScopes |
| 3681 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3682 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3683 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3684 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3685 | if (mService != null) { |
| 3686 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3687 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3688 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3689 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | return false; |
| 3693 | } |
| 3694 | |
| 3695 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3696 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3697 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3698 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3699 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3700 | * security exception will be thrown. |
| 3701 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3702 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3703 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3704 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3705 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3706 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3707 | * @see #setDelegatedScopes |
| 3708 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3709 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3710 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3711 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3712 | if (mService != null) { |
| 3713 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3714 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3715 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3716 | } catch (CertificateException e) { |
| 3717 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3718 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3719 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3720 | } |
| 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3725 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3726 | * If a user has installed any certificates by other means than device policy these will be |
| 3727 | * included too. |
| 3728 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3729 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3730 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3731 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3732 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3733 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3734 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3735 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3736 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3737 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3738 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3739 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3740 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3741 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3742 | for (String alias : certStore.userAliases()) { |
| 3743 | try { |
| 3744 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3745 | } catch (CertificateException ce) { |
| 3746 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3747 | } |
| 3748 | } |
| 3749 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3750 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3751 | } |
| 3752 | } |
| 3753 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3757 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3758 | * means other than device policy will also be removed, except for system CA certificates. |
| 3759 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3760 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3761 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3762 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3763 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3764 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3765 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3766 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3767 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3768 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3769 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3770 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3771 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3772 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3773 | } |
| 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | /** |
| 3778 | * Returns whether this certificate is installed as a trusted CA. |
| 3779 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3780 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3781 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3782 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3783 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3784 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3785 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3786 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3787 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3788 | if (mService != null) { |
| 3789 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3790 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3791 | return getCaCertAlias(certBuffer) != null; |
| 3792 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3793 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3794 | } catch (CertificateException ce) { |
| 3795 | Log.w(TAG, "Could not parse certificate", ce); |
| 3796 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3797 | } |
| 3798 | return false; |
| 3799 | } |
| 3800 | |
| 3801 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3802 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3803 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3804 | * the certificate and use the private key, given direct user approval. |
| 3805 | * |
| 3806 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3807 | * direct user approval. This is for security - should a certificate installer become |
| 3808 | * compromised, certificates it had already installed will be protected. |
| 3809 | * |
| 3810 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3811 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3812 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3813 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3814 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3815 | * @param privKey The private key to install. |
| 3816 | * @param cert The certificate to install. |
| 3817 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3818 | * with that alias already exists, it will be overwritten. |
| 3819 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3820 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3821 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3822 | * @see #setDelegatedScopes |
| 3823 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3824 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3825 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3826 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3827 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | /** |
| 3831 | * 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] | 3832 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3833 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3834 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3835 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3836 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3837 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3838 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3839 | * |
| 3840 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3841 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3842 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3843 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3844 | * certificate and include the chain of trust in order. This will be returned by |
| 3845 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3846 | * @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] | 3847 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3848 | * @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] | 3849 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3850 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3851 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3852 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3853 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3854 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3855 | * @see #setDelegatedScopes |
| 3856 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3857 | */ |
| 3858 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3859 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3860 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3861 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3862 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3863 | byte[] pemChain = null; |
| 3864 | if (certs.length > 1) { |
| 3865 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3866 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3867 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3868 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3869 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3870 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3871 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3872 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3873 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3874 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3875 | } catch (CertificateException | IOException e) { |
| 3876 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3877 | } |
| 3878 | return false; |
| 3879 | } |
| 3880 | |
| 3881 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3882 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3883 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3884 | * |
| 3885 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3886 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3887 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3888 | * @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] | 3889 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3890 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3891 | * @see #setDelegatedScopes |
| 3892 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3893 | */ |
| 3894 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3895 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3896 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3897 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3898 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3899 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3900 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3904 | * @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] | 3905 | * doesn't exist. |
| 3906 | */ |
| 3907 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3908 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3909 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3910 | new ByteArrayInputStream(certBuffer)); |
| 3911 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3912 | } |
| 3913 | |
| 3914 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3915 | * 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] | 3916 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3917 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3918 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3919 | * <p> |
| 3920 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3921 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3922 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3923 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3924 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3925 | * 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] | 3926 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3927 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3928 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3929 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3930 | * @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] | 3931 | * access. If {@code null} is given the current package will be cleared. |
| 3932 | * @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] | 3933 | * |
| 3934 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 3935 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3936 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3937 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3938 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3939 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3940 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3941 | if (mService != null) { |
| 3942 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3943 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3944 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3945 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3946 | } |
| 3947 | } |
| 3948 | } |
| 3949 | |
| 3950 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3951 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3952 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3953 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3954 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3955 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3956 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3957 | * none is set. |
| 3958 | * @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] | 3959 | * |
| 3960 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3961 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3962 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3963 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3964 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3965 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3966 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3967 | if (mService != null) { |
| 3968 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3969 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3970 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3971 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3972 | } |
| 3973 | } |
| 3974 | return null; |
| 3975 | } |
| 3976 | |
| 3977 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3978 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3979 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3980 | * constants. |
| 3981 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3982 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 3983 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 3984 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 3985 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 3986 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3987 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3988 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3989 | * {@code delegatePackage}. |
| 3990 | * |
| 3991 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3992 | * @param delegatePackage The package name of the app which will be given access. |
| 3993 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3994 | * {@code delegatedPackage}. |
| 3995 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3996 | */ |
| 3997 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3998 | @NonNull List<String> scopes) { |
| 3999 | throwIfParentInstance("setDelegatedScopes"); |
| 4000 | if (mService != null) { |
| 4001 | try { |
| 4002 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 4003 | } catch (RemoteException e) { |
| 4004 | throw e.rethrowFromSystemServer(); |
| 4005 | } |
| 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | /** |
| 4010 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 4011 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 4012 | * passing {@code null} for {@code admin} and their own package name as |
| 4013 | * {@code delegatedPackage}. |
| 4014 | * |
| 4015 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4016 | * {@code null} if the caller is {@code delegatedPackage}. |
| 4017 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 4018 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 4019 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 4020 | */ |
| 4021 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 4022 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4023 | @NonNull String delegatedPackage) { |
| 4024 | throwIfParentInstance("getDelegatedScopes"); |
| 4025 | if (mService != null) { |
| 4026 | try { |
| 4027 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 4028 | } catch (RemoteException e) { |
| 4029 | throw e.rethrowFromSystemServer(); |
| 4030 | } |
| 4031 | } |
| 4032 | return null; |
| 4033 | } |
| 4034 | |
| 4035 | /** |
| 4036 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 4037 | * granted a delegation scope. |
| 4038 | * |
| 4039 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4040 | * @param delegationScope The scope whose delegates should be retrieved. |
| 4041 | * @return A list of package names of the current delegated packages for |
| 4042 | {@code delegationScope}. |
| 4043 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 4044 | */ |
| 4045 | @Nullable |
| 4046 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 4047 | @NonNull String delegationScope) { |
| 4048 | throwIfParentInstance("getDelegatePackages"); |
| 4049 | if (mService != null) { |
| 4050 | try { |
| 4051 | return mService.getDelegatePackages(admin, delegationScope); |
| 4052 | } catch (RemoteException e) { |
| 4053 | throw e.rethrowFromSystemServer(); |
| 4054 | } |
| 4055 | } |
| 4056 | return null; |
| 4057 | } |
| 4058 | |
| 4059 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4060 | * 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] | 4061 | * specific application for the current user. This connection is automatically granted and |
| 4062 | * persisted after a reboot. |
| 4063 | * <p> |
Charles He | 3673863 | 2017-05-15 17:07:18 +0100 | [diff] [blame] | 4064 | * To support the always-on feature, an app must |
| 4065 | * <ul> |
| 4066 | * <li>declare a {@link android.net.VpnService} in its manifest, guarded by |
| 4067 | * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li> |
| 4068 | * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li> |
| 4069 | * <li><i>not</i> explicitly opt out of the feature through |
Charles He | c57a01c | 2017-08-15 15:30:22 +0100 | [diff] [blame] | 4070 | * {@link android.net.VpnService#SERVICE_META_DATA_SUPPORTS_ALWAYS_ON}.</li> |
Charles He | 3673863 | 2017-05-15 17:07:18 +0100 | [diff] [blame] | 4071 | * </ul> |
| 4072 | * The call will fail if called with the package name of an unsupported VPN app. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4073 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4074 | * @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] | 4075 | * remove an existing always-on VPN configuration. |
| 4076 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 4077 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 4078 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4079 | * @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] | 4080 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 4081 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 4082 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4083 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 4084 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 4085 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 4086 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4087 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4088 | if (mService != null) { |
| 4089 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 4090 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 4091 | throw new NameNotFoundException(vpnPackage); |
| 4092 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4093 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4094 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4095 | } |
| 4096 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | /** |
| 4100 | * 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] | 4101 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 4102 | * 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] | 4103 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4104 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 4105 | * is set. |
| 4106 | * @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] | 4107 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4108 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4109 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4110 | if (mService != null) { |
| 4111 | try { |
| 4112 | return mService.getAlwaysOnVpnPackage(admin); |
| 4113 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4114 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 4115 | } |
| 4116 | } |
| 4117 | return null; |
| 4118 | } |
| 4119 | |
| 4120 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4121 | * Called by an application that is administering the device to disable all cameras on the |
| 4122 | * device, for this user. After setting this, no applications running as this user will be able |
| 4123 | * to access any cameras on the device. |
| 4124 | * <p> |
| 4125 | * If the caller is device owner, then the restriction will be applied to all users. |
| 4126 | * <p> |
| 4127 | * The calling device admin must have requested |
| 4128 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 4129 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4130 | * |
| 4131 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4132 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4133 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4134 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4135 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4136 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4137 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4138 | if (mService != null) { |
| 4139 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4140 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4141 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4142 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4143 | } |
| 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4148 | * 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] | 4149 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4150 | * @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] | 4151 | * have disabled the camera |
| 4152 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4153 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4154 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4155 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4159 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4160 | if (mService != null) { |
| 4161 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4162 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4163 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4164 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | return false; |
| 4168 | } |
| 4169 | |
| 4170 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4171 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4172 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 4173 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 4174 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 4175 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4176 | * |
| 4177 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4178 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 4179 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 4180 | * 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] | 4181 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 4182 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4183 | */ |
| 4184 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4185 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4186 | if (mService != null) { |
| 4187 | try { |
| 4188 | return mService.requestBugreport(admin); |
| 4189 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4190 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4191 | } |
| 4192 | } |
| 4193 | return false; |
| 4194 | } |
| 4195 | |
| 4196 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 4197 | * Determine whether or not creating a guest user has been disabled for the device |
| 4198 | * |
| 4199 | * @hide |
| 4200 | */ |
| 4201 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 4202 | // Currently guest users can always be created if multi-user is enabled |
| 4203 | // TODO introduce a policy for guest user creation |
| 4204 | return false; |
| 4205 | } |
| 4206 | |
| 4207 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 4208 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 4209 | * screen capture also prevents the content from being shown on display devices that do not have |
| 4210 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 4211 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4212 | * <p> |
| 4213 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4214 | * exception will be thrown. |
| 4215 | * <p> |
| 4216 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 4217 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 4218 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4219 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4220 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4221 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4222 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4223 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4224 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4225 | if (mService != null) { |
| 4226 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4227 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4228 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4229 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4230 | } |
| 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4235 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4236 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4237 | * @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] | 4238 | * have disabled screen capture. |
| 4239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4240 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4241 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4242 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4246 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4247 | if (mService != null) { |
| 4248 | try { |
| 4249 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 4250 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4251 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4252 | } |
| 4253 | } |
| 4254 | return false; |
| 4255 | } |
| 4256 | |
| 4257 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4258 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 4259 | * 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] | 4260 | * <p> |
| 4261 | * Note: if auto time is required the user can still manually set the time zone. |
| 4262 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4263 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4264 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4265 | * |
| 4266 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4267 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4268 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4269 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4270 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4271 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4272 | if (mService != null) { |
| 4273 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4274 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4275 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4276 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4277 | } |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | /** |
| 4282 | * @return true if auto time is required. |
| 4283 | */ |
| 4284 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4285 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4286 | if (mService != null) { |
| 4287 | try { |
| 4288 | return mService.getAutoTimeRequired(); |
| 4289 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4290 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | return false; |
| 4294 | } |
| 4295 | |
| 4296 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4297 | * 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] | 4298 | * <p> |
| 4299 | * The system user is exempt from this policy - it is never ephemeral. |
| 4300 | * <p> |
| 4301 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4302 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4303 | * |
| 4304 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4305 | * @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] | 4306 | * subsequently created users will be ephemeral. |
| 4307 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4308 | * @hide |
| 4309 | */ |
| 4310 | public void setForceEphemeralUsers( |
| 4311 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4312 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4313 | if (mService != null) { |
| 4314 | try { |
| 4315 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 4316 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4317 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4318 | } |
| 4319 | } |
| 4320 | } |
| 4321 | |
| 4322 | /** |
| 4323 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4324 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4325 | * @hide |
| 4326 | */ |
| 4327 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4328 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4329 | if (mService != null) { |
| 4330 | try { |
| 4331 | return mService.getForceEphemeralUsers(admin); |
| 4332 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4333 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | return false; |
| 4337 | } |
| 4338 | |
| 4339 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4340 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4341 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4342 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4343 | * <p> |
| 4344 | * The calling device admin must have requested |
| 4345 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4346 | * if it has not, a security exception will be thrown. |
| 4347 | * <p> |
| 4348 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4349 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4350 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4351 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4352 | * <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] | 4353 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4354 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4355 | * there is one, or the parent user otherwise. |
| 4356 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4357 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4358 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4359 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4360 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4361 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4362 | * profile. |
| 4363 | * <p> |
| 4364 | * Requests to disable other features on a managed profile will be ignored. |
| 4365 | * <p> |
| 4366 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4367 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4368 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4369 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4370 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4371 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4372 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4373 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4374 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4375 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4376 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4377 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4378 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4379 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4380 | if (mService != null) { |
| 4381 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4382 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4383 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4384 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4385 | } |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4390 | * 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] | 4391 | * 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] | 4392 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4393 | * |
| 4394 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4395 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4396 | * restrictions on the parent profile. |
| 4397 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4398 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4399 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4400 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4401 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4402 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4403 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4404 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4408 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4409 | if (mService != null) { |
| 4410 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4411 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4412 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4413 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4414 | } |
| 4415 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4416 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4420 | * @hide |
| 4421 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4422 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4423 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4424 | if (mService != null) { |
| 4425 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4426 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4427 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4428 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4429 | } |
| 4430 | } |
| 4431 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4432 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4433 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4434 | * @hide |
| 4435 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4436 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4437 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4441 | * @hide |
| 4442 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4443 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4444 | if (mService != null) { |
| 4445 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4446 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4447 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4448 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | /** |
| 4454 | * @hide |
| 4455 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4456 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4457 | if (mService != null) { |
| 4458 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4459 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4460 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4461 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4462 | } |
| 4463 | } |
| 4464 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4465 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4466 | /** |
| 4467 | * @hide |
| 4468 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4469 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4470 | if (mService != null) { |
| 4471 | try { |
| 4472 | mService.reportPasswordChanged(userId); |
| 4473 | } catch (RemoteException e) { |
| 4474 | throw e.rethrowFromSystemServer(); |
| 4475 | } |
| 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | /** |
| 4480 | * @hide |
| 4481 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4482 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4483 | if (mService != null) { |
| 4484 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4485 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4486 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4487 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4488 | } |
| 4489 | } |
| 4490 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4491 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4492 | /** |
| 4493 | * @hide |
| 4494 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4495 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4496 | if (mService != null) { |
| 4497 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4498 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4499 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4500 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4504 | |
| 4505 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4506 | * @hide |
| 4507 | */ |
| 4508 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4509 | if (mService != null) { |
| 4510 | try { |
| 4511 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4512 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4513 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | /** |
| 4519 | * @hide |
| 4520 | */ |
| 4521 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4522 | if (mService != null) { |
| 4523 | try { |
| 4524 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4525 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4526 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4527 | } |
| 4528 | } |
| 4529 | } |
| 4530 | |
| 4531 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4532 | * Should be called when keyguard has been dismissed. |
| 4533 | * @hide |
| 4534 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4535 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4536 | if (mService != null) { |
| 4537 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4538 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4539 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4540 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4541 | } |
| 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | /** |
| 4546 | * Should be called when keyguard view has been shown to the user. |
| 4547 | * @hide |
| 4548 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4549 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4550 | if (mService != null) { |
| 4551 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4552 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4553 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4554 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4555 | } |
| 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4560 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4561 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4562 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4563 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4564 | * @return whether the package was successfully registered as the device owner. |
| 4565 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4566 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4567 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4568 | public boolean setDeviceOwner(ComponentName who) { |
| 4569 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | /** |
| 4573 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4574 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4575 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4576 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | /** |
| 4580 | * @hide |
| 4581 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4582 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4583 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | /** |
| 4587 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4588 | * Sets the given package as the device owner. The package must already be installed. There |
| 4589 | * must not already be a device owner. |
| 4590 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4591 | * this method. |
| 4592 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4593 | * 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] | 4594 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4595 | * @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] | 4596 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4597 | * @return whether the package was successfully registered as the device owner. |
| 4598 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4599 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4600 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4601 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4602 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4603 | if (mService != null) { |
| 4604 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4605 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4606 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4607 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | return false; |
| 4611 | } |
| 4612 | |
| 4613 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4614 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4615 | * 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] | 4616 | * 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] | 4617 | * package is currently registered as the device owner app, pass in the package name from |
| 4618 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4619 | * 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] | 4620 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4621 | * the setup process. |
| 4622 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4623 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4624 | * @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] | 4625 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4626 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4627 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4628 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4629 | } |
| 4630 | |
| 4631 | /** |
| 4632 | * @return true if a package is registered as device owner, only when it's running on the |
| 4633 | * calling user. |
| 4634 | * |
| 4635 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4636 | * @hide |
| 4637 | */ |
| 4638 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4639 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4644 | * user. |
| 4645 | * |
| 4646 | * <p>Requires the MANAGE_USERS permission. |
| 4647 | * |
| 4648 | * @hide |
| 4649 | */ |
| 4650 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4651 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4652 | } |
| 4653 | |
| 4654 | /** |
| 4655 | * @return device owner component name, only when it's running on the calling user. |
| 4656 | * |
| 4657 | * @hide |
| 4658 | */ |
| 4659 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4660 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4661 | } |
| 4662 | |
| 4663 | /** |
| 4664 | * @return device owner component name, even if it's running on a different user. |
| 4665 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4666 | * @hide |
| 4667 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4668 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4669 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4670 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4671 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4672 | } |
| 4673 | |
| 4674 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4675 | if (packageName == null) { |
| 4676 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4677 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4678 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4679 | if (deviceOwner == null) { |
| 4680 | return false; |
| 4681 | } |
| 4682 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4683 | } |
| 4684 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4685 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4686 | if (mService != null) { |
| 4687 | try { |
| 4688 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4689 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4690 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4691 | } |
| 4692 | } |
| 4693 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4694 | } |
| 4695 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4696 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4697 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4698 | * no device owner. |
| 4699 | * |
| 4700 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4701 | * |
| 4702 | * @hide |
| 4703 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4704 | public int getDeviceOwnerUserId() { |
| 4705 | if (mService != null) { |
| 4706 | try { |
| 4707 | return mService.getDeviceOwnerUserId(); |
| 4708 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4709 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4710 | } |
| 4711 | } |
| 4712 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4716 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4717 | * 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] | 4718 | * a part of device setup, before it completes. |
| 4719 | * <p> |
| 4720 | * While some policies previously set by the device owner will be cleared by this method, it is |
| 4721 | * a best-effort process and some other policies will still remain in place after the device |
| 4722 | * owner is cleared. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4723 | * |
| 4724 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4725 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4726 | * does not own the current device owner component. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4727 | * |
| 4728 | * @deprecated This method is expected to be used for testing purposes only. The device owner |
| 4729 | * will lose control of the device and its data after calling it. In order to protect any |
| 4730 | * sensitive data that remains on the device, it is advised that the device owner factory resets |
| 4731 | * the device instead of calling this method. See {@link #wipeData(int)}. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4732 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4733 | @Deprecated |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4734 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4735 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4736 | if (mService != null) { |
| 4737 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4738 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4739 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4740 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4741 | } |
| 4742 | } |
| 4743 | } |
| 4744 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4745 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4746 | * Returns the device owner package name, only if it's running on the calling user. |
| 4747 | * |
| 4748 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4749 | * |
| 4750 | * @hide |
| 4751 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4752 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4753 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4754 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4755 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4756 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4757 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4761 | * 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] | 4762 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4763 | * @return whether the device is managed by a Device Owner. |
| 4764 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4765 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4766 | * |
| 4767 | * @hide |
| 4768 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4769 | @SystemApi |
| 4770 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4771 | @SuppressLint("Doclava125") |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4772 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4773 | try { |
| 4774 | return mService.hasDeviceOwner(); |
| 4775 | } catch (RemoteException re) { |
| 4776 | throw re.rethrowFromSystemServer(); |
| 4777 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | /** |
| 4781 | * Returns the device owner name. Note this method *will* return the device owner |
| 4782 | * name when it's running on a different user. |
| 4783 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4784 | * @hide |
| 4785 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4786 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4787 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4788 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4789 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4790 | if (mService != null) { |
| 4791 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4792 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4793 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4794 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4795 | } |
| 4796 | } |
| 4797 | return null; |
| 4798 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4799 | |
| 4800 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4801 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4802 | * @deprecated Do not use |
| 4803 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4804 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4805 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4806 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4807 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4808 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4809 | return null; |
| 4810 | } |
| 4811 | |
| 4812 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4813 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4814 | * @deprecated Do not use |
| 4815 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4816 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4817 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4818 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4819 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4820 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4821 | return null; |
| 4822 | } |
| 4823 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4824 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4825 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4826 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4827 | * Sets the given component as an active admin and registers the package as the profile |
| 4828 | * owner for this user. The package must already be installed and there shouldn't be |
| 4829 | * an existing profile owner registered for this user. Also, this method must be called |
| 4830 | * before the user setup has been completed. |
| 4831 | * <p> |
| 4832 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4833 | * MANAGE_DEVICE_ADMINS permission. |
| 4834 | * @param admin The component to register as an active admin and profile owner. |
| 4835 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4836 | * @return whether the admin was successfully registered as the profile owner. |
| 4837 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4838 | * the user has already been set up. |
| 4839 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4840 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4841 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4842 | @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4843 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4844 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4845 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4846 | if (mService != null) { |
| 4847 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4848 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4849 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4850 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4851 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4852 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4853 | } |
| 4854 | } |
| 4855 | return false; |
| 4856 | } |
| 4857 | |
| 4858 | /** |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4859 | * Clears the active profile owner. The caller must be the profile owner of this user, otherwise |
| 4860 | * 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] | 4861 | * <p> |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4862 | * While some policies previously set by the profile owner will be cleared by this method, it is |
| 4863 | * a best-effort process and some other policies will still remain in place after the profile |
| 4864 | * owner is cleared. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4865 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4866 | * @param admin The component to remove as the profile owner. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4867 | * @throws SecurityException if {@code admin} is not an active profile owner, or the method is |
| 4868 | * being called from a managed profile. |
| 4869 | * |
| 4870 | * @deprecated This method is expected to be used for testing purposes only. The profile owner |
| 4871 | * will lose control of the user and its data after calling it. In order to protect any |
| 4872 | * sensitive data that remains on this user, it is advised that the profile owner deletes it |
| 4873 | * instead of calling this method. See {@link #wipeData(int)}. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4874 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4875 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4876 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4877 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4878 | if (mService != null) { |
| 4879 | try { |
| 4880 | mService.clearProfileOwner(admin); |
| 4881 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4882 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4883 | } |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4888 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4889 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4890 | */ |
| 4891 | public boolean hasUserSetupCompleted() { |
| 4892 | if (mService != null) { |
| 4893 | try { |
| 4894 | return mService.hasUserSetupCompleted(); |
| 4895 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4896 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4897 | } |
| 4898 | } |
| 4899 | return true; |
| 4900 | } |
| 4901 | |
| 4902 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4903 | * @hide |
| 4904 | * 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] | 4905 | * already be installed. There must not already be a profile owner for this user. |
| 4906 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4907 | * this method. |
| 4908 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4909 | * - the caller is SYSTEM_UID. |
| 4910 | * - 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] | 4911 | * @param admin the component name to be registered as profile owner. |
| 4912 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4913 | * @param userHandle the userId to set the profile owner for. |
| 4914 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4915 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4916 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4917 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4918 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4919 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4920 | if (mService != null) { |
| 4921 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4922 | if (ownerName == null) { |
| 4923 | ownerName = ""; |
| 4924 | } |
| 4925 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4926 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4927 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4928 | } |
| 4929 | } |
| 4930 | return false; |
| 4931 | } |
| 4932 | |
| 4933 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4934 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4935 | * <p> |
| 4936 | * 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] | 4937 | * 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] | 4938 | * <p> |
| 4939 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4940 | * will be blank and the user will not be allowed to change it. |
| 4941 | * <p> |
| 4942 | * 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] | 4943 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4944 | * and set a new version of this string accordingly. |
| 4945 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4946 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4947 | * @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] | 4948 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4949 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4950 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4951 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4952 | if (mService != null) { |
| 4953 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4954 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4955 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4956 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4957 | } |
| 4958 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | /** |
| 4962 | * @return The device owner information. If it is not set returns {@code null}. |
| 4963 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4964 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4965 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4966 | if (mService != null) { |
| 4967 | try { |
| 4968 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4969 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4970 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4971 | } |
| 4972 | } |
| 4973 | return null; |
| 4974 | } |
| 4975 | |
| 4976 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4977 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4978 | * called by a device owner, profile owner, or by a delegate given the |
| 4979 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4980 | * <p> |
| 4981 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4982 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4983 | * device. |
| 4984 | * <p> |
| 4985 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4986 | * 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] | 4987 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4988 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4989 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4990 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4991 | * @param packageNames The package names to suspend or unsuspend. |
| 4992 | * @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] | 4993 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4994 | * @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] | 4995 | * this method. |
| 4996 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4997 | * @see #setDelegatedScopes |
| 4998 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4999 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5000 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 5001 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5002 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5003 | if (mService != null) { |
| 5004 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5005 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 5006 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5007 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5008 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5009 | } |
| 5010 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 5011 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5015 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 5016 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 5017 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5018 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5019 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5020 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5021 | * @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] | 5022 | * @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] | 5023 | * suspended, could not be found or an error occurred. |
| 5024 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 5025 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5026 | * @see #setDelegatedScopes |
| 5027 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5028 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 5029 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 5030 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5031 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5032 | if (mService != null) { |
| 5033 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5034 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5035 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5036 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 5037 | } catch (IllegalArgumentException ex) { |
| 5038 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5039 | } |
| 5040 | } |
| 5041 | return false; |
| 5042 | } |
| 5043 | |
| 5044 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5045 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 5046 | * be used. Only the profile owner can call this. |
| 5047 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 5048 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5049 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5050 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5051 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5052 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5053 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5054 | if (mService != null) { |
| 5055 | try { |
| 5056 | mService.setProfileEnabled(admin); |
| 5057 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5058 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 5059 | } |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5064 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 5065 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 5066 | * 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] | 5067 | * |
| 5068 | * @see #isProfileOwnerApp |
| 5069 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5070 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5071 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5072 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5073 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5074 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5075 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5076 | if (mService != null) { |
| 5077 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5078 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 5079 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5080 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 5081 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5082 | } |
| 5083 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 5084 | |
| 5085 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5086 | * 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] | 5087 | * 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] | 5088 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5089 | * |
| 5090 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 5091 | * @return Whether or not the package is registered as the profile owner. |
| 5092 | */ |
| 5093 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5094 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5095 | if (mService != null) { |
| 5096 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 5097 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 5098 | return profileOwner != null |
| 5099 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5100 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5101 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | return false; |
| 5105 | } |
| 5106 | |
| 5107 | /** |
| 5108 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5109 | * @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] | 5110 | * owner has been set for that user. |
| 5111 | * @throws IllegalArgumentException if the userId is invalid. |
| 5112 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 5113 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5114 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5115 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 5116 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 5117 | } |
| 5118 | |
| 5119 | /** |
| 5120 | * @see #getProfileOwner() |
| 5121 | * @hide |
| 5122 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5123 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 5124 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5125 | if (mService != null) { |
| 5126 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 5127 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5128 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5129 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5130 | } |
| 5131 | } |
| 5132 | return null; |
| 5133 | } |
| 5134 | |
| 5135 | /** |
| 5136 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5137 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 5138 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5139 | * @throws IllegalArgumentException if the userId is invalid. |
| 5140 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5141 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5142 | if (mService != null) { |
| 5143 | try { |
| 5144 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 5145 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5146 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5147 | } |
| 5148 | } |
| 5149 | return null; |
| 5150 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5151 | |
| 5152 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5153 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5154 | * @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] | 5155 | * @return the human readable name of the organisation associated with this profile owner or |
| 5156 | * null if one is not set. |
| 5157 | * @throws IllegalArgumentException if the userId is invalid. |
| 5158 | */ |
| 5159 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5160 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5161 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5162 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5163 | if (mService != null) { |
| 5164 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 5165 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5166 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5167 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5168 | } |
| 5169 | } |
| 5170 | return null; |
| 5171 | } |
| 5172 | |
| 5173 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5174 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 5175 | * intents that match a certain intent filter. This activity will remain the default intent |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5176 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 5177 | * intent preferences are reset. |
| 5178 | * <p> |
| 5179 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 5180 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 5181 | * the filter. |
| 5182 | * <p> |
| 5183 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 5184 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5185 | * |
| 5186 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5187 | * @param filter The IntentFilter for which a default handler is added. |
| 5188 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5189 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5190 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5191 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 5192 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5193 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5194 | if (mService != null) { |
| 5195 | try { |
| 5196 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 5197 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5198 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5199 | } |
| 5200 | } |
| 5201 | } |
| 5202 | |
| 5203 | /** |
| 5204 | * 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] | 5205 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5206 | * <p> |
| 5207 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5208 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5209 | * |
| 5210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5211 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5212 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5213 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5214 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5215 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5216 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5217 | if (mService != null) { |
| 5218 | try { |
| 5219 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 5220 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5221 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5222 | } |
| 5223 | } |
| 5224 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5225 | |
| 5226 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5227 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 5228 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 5229 | * {@link #getApplicationRestrictions}. |
| 5230 | * <p> |
| 5231 | * This permission is persistent until it is later cleared by calling this method with a |
| 5232 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 5233 | * <p> |
| 5234 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5235 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5236 | * |
| 5237 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5238 | * @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] | 5239 | * APIs. If {@code null} is given the current package will be cleared. |
| 5240 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5241 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5242 | * |
| 5243 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 5244 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5245 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5246 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5247 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5248 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5249 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5250 | if (mService != null) { |
| 5251 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5252 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 5253 | throw new NameNotFoundException(packageName); |
| 5254 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5255 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5256 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5257 | } |
| 5258 | } |
| 5259 | } |
| 5260 | |
| 5261 | /** |
| 5262 | * 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] | 5263 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 5264 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5265 | * |
| 5266 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5267 | * @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] | 5268 | * {@code null} if none is set. |
| 5269 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5270 | * |
| 5271 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 5272 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5273 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5274 | @Deprecated |
| 5275 | @Nullable |
| 5276 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5277 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5278 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5279 | if (mService != null) { |
| 5280 | try { |
| 5281 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 5282 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5283 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5284 | } |
| 5285 | } |
| 5286 | return null; |
| 5287 | } |
| 5288 | |
| 5289 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 5290 | * Called by any application to find out whether it has been granted permission via |
| 5291 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 5292 | * for the calling user. |
| 5293 | * |
| 5294 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 5295 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5296 | * |
| 5297 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 5298 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5299 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5300 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5301 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5302 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5303 | if (mService != null) { |
| 5304 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5305 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 5306 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5307 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5308 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5309 | } |
| 5310 | } |
| 5311 | return false; |
| 5312 | } |
| 5313 | |
| 5314 | /** |
| 5315 | * 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] | 5316 | * <p> |
| 5317 | * 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] | 5318 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5319 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5320 | * <p> |
| 5321 | * 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] | 5322 | * <ul> |
| 5323 | * <li>{@code boolean} |
| 5324 | * <li>{@code int} |
| 5325 | * <li>{@code String} or {@code String[]} |
| 5326 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5327 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5328 | * <p> |
| 5329 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5330 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5331 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5332 | * <p> |
| 5333 | * The application restrictions are only made visible to the target application via |
| 5334 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5335 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5336 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5337 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5338 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5339 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5340 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5341 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5342 | * @param packageName The name of the package to update restricted settings for. |
| 5343 | * @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] | 5344 | * set of active restrictions. |
| 5345 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5346 | * @see #setDelegatedScopes |
| 5347 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5348 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5349 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5350 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5351 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5352 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5353 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5354 | if (mService != null) { |
| 5355 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5356 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5357 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5358 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5359 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5360 | } |
| 5361 | } |
| 5362 | } |
| 5363 | |
| 5364 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5365 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 5366 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5367 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5368 | * {@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] | 5369 | * <p> |
| 5370 | * The calling device admin must have requested |
| 5371 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5372 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5373 | * <p> |
| 5374 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5375 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5376 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5377 | * |
| 5378 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5379 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5380 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5381 | * strictly disabled according to the state of the |
| 5382 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5383 | * <p> |
| 5384 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5385 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5386 | * device admins. |
| 5387 | * <p> |
| 5388 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5389 | * parameters. |
| 5390 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5391 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5392 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5393 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5394 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5395 | if (mService != null) { |
| 5396 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5397 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5398 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5399 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5400 | } |
| 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5405 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5406 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5407 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5408 | * <p> |
| 5409 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5410 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5411 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5412 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5413 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5414 | * this function returns a list of configurations for all admins that declare |
| 5415 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5416 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5417 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5418 | * 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] | 5419 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5420 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5421 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5422 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5423 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5424 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5428 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5429 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5430 | if (mService != null) { |
| 5431 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5432 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5433 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5434 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5435 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5436 | } |
| 5437 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5438 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5442 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5443 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5444 | * <p> |
| 5445 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5446 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5447 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5448 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5449 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5450 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5451 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5452 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5453 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5454 | if (mService != null) { |
| 5455 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5456 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5457 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5458 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5459 | } |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5464 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5465 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5466 | * <p> |
| 5467 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5468 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5469 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5470 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5471 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5472 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5473 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5474 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5475 | if (mService != null) { |
| 5476 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5477 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5478 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5479 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5480 | } |
| 5481 | } |
| 5482 | return false; |
| 5483 | } |
| 5484 | |
| 5485 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5486 | * Determine whether or not caller-Id information has been disabled. |
| 5487 | * |
| 5488 | * @param userHandle The user for whom to check the caller-id permission |
| 5489 | * @hide |
| 5490 | */ |
| 5491 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5492 | if (mService != null) { |
| 5493 | try { |
| 5494 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5495 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5496 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5497 | } |
| 5498 | } |
| 5499 | return false; |
| 5500 | } |
| 5501 | |
| 5502 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5503 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5504 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5505 | * <p> |
| 5506 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5507 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5508 | * |
| 5509 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5510 | * @param disabled If true contacts search in the managed profile is not displayed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5511 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5512 | */ |
| 5513 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5514 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5515 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5516 | if (mService != null) { |
| 5517 | try { |
| 5518 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5519 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5520 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5521 | } |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | /** |
| 5526 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5527 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5528 | * <p> |
| 5529 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5530 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5531 | * |
| 5532 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5533 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5534 | */ |
| 5535 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5536 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5537 | if (mService != null) { |
| 5538 | try { |
| 5539 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 5540 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5541 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5542 | } |
| 5543 | } |
| 5544 | return false; |
| 5545 | } |
| 5546 | |
| 5547 | |
| 5548 | /** |
| 5549 | * Determine whether or not contacts search has been disabled. |
| 5550 | * |
| 5551 | * @param userHandle The user for whom to check the contacts search permission |
| 5552 | * @hide |
| 5553 | */ |
| 5554 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5555 | if (mService != null) { |
| 5556 | try { |
| 5557 | return mService |
| 5558 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5559 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5560 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5561 | } |
| 5562 | } |
| 5563 | return false; |
| 5564 | } |
| 5565 | |
| 5566 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5567 | * 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] | 5568 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5569 | * @hide |
| 5570 | */ |
| 5571 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5572 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5573 | if (mService != null) { |
| 5574 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5575 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5576 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5577 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5578 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5579 | } |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5584 | * 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] | 5585 | * @hide |
| 5586 | */ |
| 5587 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5588 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5589 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5590 | originalIntent); |
| 5591 | } |
| 5592 | |
| 5593 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5594 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5595 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5596 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5597 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5598 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5599 | * <p> |
| 5600 | * This API works on managed profile only. |
| 5601 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5602 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5603 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5604 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5605 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5606 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5607 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5608 | if (mService != null) { |
| 5609 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5610 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5611 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5612 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5613 | } |
| 5614 | } |
| 5615 | } |
| 5616 | |
| 5617 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5618 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5619 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5620 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5621 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5622 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5623 | * <p> |
| 5624 | * This API works on managed profile only. |
| 5625 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5626 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5627 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5628 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5629 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5630 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5631 | if (mService != null) { |
| 5632 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5633 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5634 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5635 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5636 | } |
| 5637 | } |
| 5638 | return true; |
| 5639 | } |
| 5640 | |
| 5641 | /** |
| 5642 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5643 | * <p> |
| 5644 | * This API works on managed profile UserHandle only. |
| 5645 | * |
| 5646 | * @param userHandle The user for whom to check the caller-id permission |
| 5647 | * @hide |
| 5648 | */ |
| 5649 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5650 | if (mService != null) { |
| 5651 | try { |
| 5652 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5653 | .getIdentifier()); |
| 5654 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5655 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5656 | } |
| 5657 | } |
| 5658 | return true; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5662 | * 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] | 5663 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5664 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5665 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5666 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5667 | * @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] | 5668 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5669 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5670 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5671 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5672 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5673 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5674 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5675 | if (mService != null) { |
| 5676 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5677 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5678 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5679 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5680 | } |
| 5681 | } |
| 5682 | } |
| 5683 | |
| 5684 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5685 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5686 | * 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] | 5687 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5688 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5689 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5690 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5691 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5692 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5693 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5694 | if (mService != null) { |
| 5695 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5696 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5697 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5698 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5699 | } |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5704 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5705 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5706 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5707 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5708 | * the list and not part of the system can not be enabled by the user. |
| 5709 | * <p> |
| 5710 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5711 | * used, calling with an empty list only allows the builtin system's services. |
| 5712 | * <p> |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5713 | * 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] | 5714 | * |
| 5715 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5716 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5717 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5718 | * accessibility services enabled, that are not in the list. |
| 5719 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5720 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5721 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5722 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5723 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5724 | if (mService != null) { |
| 5725 | try { |
| 5726 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5727 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5728 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5729 | } |
| 5730 | } |
| 5731 | return false; |
| 5732 | } |
| 5733 | |
| 5734 | /** |
| 5735 | * 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] | 5736 | * <p> |
| 5737 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5738 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5739 | * |
| 5740 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5741 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5742 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5743 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5744 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5745 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5746 | if (mService != null) { |
| 5747 | try { |
| 5748 | return mService.getPermittedAccessibilityServices(admin); |
| 5749 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5750 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5751 | } |
| 5752 | } |
| 5753 | return null; |
| 5754 | } |
| 5755 | |
| 5756 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5757 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5758 | * |
| 5759 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5760 | * @param packageName Accessibility service package name that needs to be checked. |
| 5761 | * @param userHandle user id the admin is running as. |
| 5762 | * @return true if the accessibility service is permitted, otherwise false. |
| 5763 | * |
| 5764 | * @hide |
| 5765 | */ |
| 5766 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5767 | @NonNull String packageName, int userHandle) { |
| 5768 | if (mService != null) { |
| 5769 | try { |
| 5770 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5771 | userHandle); |
| 5772 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5773 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5774 | } |
| 5775 | } |
| 5776 | return false; |
| 5777 | } |
| 5778 | |
| 5779 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5780 | * Returns the list of accessibility services permitted by the device or profiles |
| 5781 | * owners of this user. |
| 5782 | * |
| 5783 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5784 | * it will contain the intersection of the permitted lists for any device or profile |
| 5785 | * owners that apply to this user. It will also include any system accessibility services. |
| 5786 | * |
| 5787 | * @param userId which user to check for. |
| 5788 | * @return List of accessiblity service package names. |
| 5789 | * @hide |
| 5790 | */ |
| 5791 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5792 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5793 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5794 | if (mService != null) { |
| 5795 | try { |
| 5796 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5797 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5798 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5799 | } |
| 5800 | } |
| 5801 | return null; |
| 5802 | } |
| 5803 | |
| 5804 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5805 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5806 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5807 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5808 | * When zero or more packages have been added, input method that are not in the list and not |
| 5809 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5810 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5811 | * <p> |
| 5812 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5813 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5814 | * <p> |
| 5815 | * 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] | 5816 | * |
| 5817 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5818 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5819 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5820 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5821 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5822 | */ |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5823 | public boolean setPermittedInputMethods( |
| 5824 | @NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5825 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5826 | if (mService != null) { |
| 5827 | try { |
| 5828 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5829 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5830 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5831 | } |
| 5832 | } |
| 5833 | return false; |
| 5834 | } |
| 5835 | |
| 5836 | |
| 5837 | /** |
| 5838 | * 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] | 5839 | * <p> |
| 5840 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5841 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5842 | * |
| 5843 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5844 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5845 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5846 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5847 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5848 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5849 | if (mService != null) { |
| 5850 | try { |
| 5851 | return mService.getPermittedInputMethods(admin); |
| 5852 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5853 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5854 | } |
| 5855 | } |
| 5856 | return null; |
| 5857 | } |
| 5858 | |
| 5859 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5860 | * Called by the system to check if a specific input method is disabled by admin. |
| 5861 | * |
| 5862 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5863 | * @param packageName Input method package name that needs to be checked. |
| 5864 | * @param userHandle user id the admin is running as. |
| 5865 | * @return true if the input method is permitted, otherwise false. |
| 5866 | * |
| 5867 | * @hide |
| 5868 | */ |
| 5869 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5870 | @NonNull String packageName, int userHandle) { |
| 5871 | if (mService != null) { |
| 5872 | try { |
| 5873 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5874 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5875 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5876 | } |
| 5877 | } |
| 5878 | return false; |
| 5879 | } |
| 5880 | |
| 5881 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5882 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5883 | * 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] | 5884 | * |
| 5885 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5886 | * it will contain the intersection of the permitted lists for any device or profile |
| 5887 | * owners that apply to this user. It will also include any system input methods. |
| 5888 | * |
| 5889 | * @return List of input method package names. |
| 5890 | * @hide |
| 5891 | */ |
| 5892 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5893 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5894 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5895 | if (mService != null) { |
| 5896 | try { |
| 5897 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5898 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5899 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5900 | } |
| 5901 | } |
| 5902 | return null; |
| 5903 | } |
| 5904 | |
| 5905 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5906 | * Called by a profile owner of a managed profile to set the packages that are allowed to use |
| 5907 | * a {@link android.service.notification.NotificationListenerService} in the primary user to |
| 5908 | * see notifications from the managed profile. By default all packages are permitted by this |
| 5909 | * policy. When zero or more packages have been added, notification listeners installed on the |
| 5910 | * primary user that are not in the list and are not part of the system won't receive events |
| 5911 | * for managed profile notifications. |
| 5912 | * <p> |
| 5913 | * Calling with a {@code null} value for the list disables the restriction so that all |
| 5914 | * notification listener services be used. Calling with an empty list disables all but the |
| 5915 | * system's own notification listeners. System notification listener services are always |
| 5916 | * available to the user. |
| 5917 | * <p> |
| 5918 | * If a device or profile owner want to stop notification listeners in their user from seeing |
| 5919 | * that user's notifications they should prevent that service from running instead (e.g. via |
| 5920 | * {@link #setApplicationHidden(ComponentName, String, boolean)}) |
| 5921 | * |
| 5922 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5923 | * @param packageList List of package names to whitelist |
| 5924 | * @return true if setting the restriction succeeded. It will fail if called outside a managed |
| 5925 | * profile |
| 5926 | * @throws SecurityException if {@code admin} is not a profile owner. |
| 5927 | * |
| 5928 | * @see android.service.notification.NotificationListenerService |
| 5929 | */ |
| 5930 | public boolean setPermittedCrossProfileNotificationListeners( |
| 5931 | @NonNull ComponentName admin, @Nullable List<String> packageList) { |
| 5932 | throwIfParentInstance("setPermittedCrossProfileNotificationListeners"); |
| 5933 | if (mService != null) { |
| 5934 | try { |
| 5935 | return mService.setPermittedCrossProfileNotificationListeners(admin, packageList); |
| 5936 | } catch (RemoteException e) { |
| 5937 | throw e.rethrowFromSystemServer(); |
| 5938 | } |
| 5939 | } |
| 5940 | return false; |
| 5941 | } |
| 5942 | |
| 5943 | /** |
| 5944 | * Returns the list of packages installed on the primary user that allowed to use a |
| 5945 | * {@link android.service.notification.NotificationListenerService} to receive |
| 5946 | * notifications from this managed profile, as set by the profile owner. |
| 5947 | * <p> |
| 5948 | * An empty list means no notification listener services except system ones are allowed. |
| 5949 | * A {@code null} return value indicates that all notification listeners are allowed. |
| 5950 | */ |
| 5951 | public @Nullable List<String> getPermittedCrossProfileNotificationListeners( |
| 5952 | @NonNull ComponentName admin) { |
| 5953 | throwIfParentInstance("getPermittedCrossProfileNotificationListeners"); |
| 5954 | if (mService != null) { |
| 5955 | try { |
| 5956 | return mService.getPermittedCrossProfileNotificationListeners(admin); |
| 5957 | } catch (RemoteException e) { |
| 5958 | throw e.rethrowFromSystemServer(); |
| 5959 | } |
| 5960 | } |
| 5961 | return null; |
| 5962 | } |
| 5963 | |
| 5964 | /** |
| 5965 | * Returns true if {@code NotificationListenerServices} from the given package are allowed to |
| 5966 | * receive events for notifications from the given user id. Can only be called by the system uid |
| 5967 | * |
| 5968 | * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List) |
| 5969 | * |
| 5970 | * @hide |
| 5971 | */ |
| 5972 | public boolean isNotificationListenerServicePermitted( |
| 5973 | @NonNull String packageName, @UserIdInt int userId) { |
| 5974 | if (mService != null) { |
| 5975 | try { |
| 5976 | return mService.isNotificationListenerServicePermitted(packageName, userId); |
| 5977 | } catch (RemoteException e) { |
| 5978 | throw e.rethrowFromSystemServer(); |
| 5979 | } |
| 5980 | } |
| 5981 | return true; |
| 5982 | } |
| 5983 | |
| 5984 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5985 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 5986 | * function can be called by a device owner or by a delegate given the |
| 5987 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 5988 | * <p> |
| 5989 | * 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] | 5990 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5991 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5992 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5993 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5994 | * @see #setDelegatedScopes |
| 5995 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5996 | * @hide |
| 5997 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5998 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5999 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6000 | if (mService != null) { |
| 6001 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6002 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6003 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6004 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6005 | } |
| 6006 | } |
| 6007 | return null; |
| 6008 | } |
| 6009 | |
| 6010 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6011 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 6012 | * function can be called by a device owner or by a delegate given the |
| 6013 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6014 | * |
| 6015 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 6016 | * automatically pre-cached.</p> |
| 6017 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6018 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6019 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6020 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6021 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6022 | * @see #setDelegatedScopes |
| 6023 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6024 | * @hide |
| 6025 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6026 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6027 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6028 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6029 | if (mService != null) { |
| 6030 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6031 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6032 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6033 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 6034 | } |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6039 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 6040 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 6041 | * created. If you need to persist an identifier for this user, use |
| 6042 | * {@link UserManager#getSerialNumberForUser}. |
| 6043 | * |
| 6044 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6045 | * @param name the user's name |
| 6046 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6047 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6048 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6049 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6050 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 6051 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6052 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6053 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6054 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6055 | return null; |
| 6056 | } |
| 6057 | |
| 6058 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 6059 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 6060 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 6061 | * created. If you need to persist an identifier for this user, use |
| 6062 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 6063 | * immediately. |
| 6064 | * |
| 6065 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 6066 | * as registered as an active admin on the new user. The profile owner package will be |
| 6067 | * installed on the new user if it already is installed on the device. |
| 6068 | * |
| 6069 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 6070 | * profileOwnerComponent when onEnable is called. |
| 6071 | * |
| 6072 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6073 | * @param name the user's name |
| 6074 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 6075 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 6076 | * the user. |
| 6077 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 6078 | * on the new user. |
| 6079 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6080 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6081 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6082 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6083 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 6084 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 6085 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 6086 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6087 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6088 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 6089 | return null; |
| 6090 | } |
| 6091 | |
| 6092 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6093 | * 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] | 6094 | */ |
| 6095 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 6096 | |
| 6097 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 6098 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 6099 | * ephemeral. |
| 6100 | * @hide |
| 6101 | */ |
| 6102 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 6103 | |
| 6104 | /** |
Christine Franks | 361b825 | 2017-06-23 18:12:46 -0700 | [diff] [blame] | 6105 | * Flag used by {@link #createAndManageUser} to specify that the user should be created as a |
| 6106 | * demo user. |
| 6107 | * @hide |
| 6108 | */ |
| 6109 | public static final int MAKE_USER_DEMO = 0x0004; |
| 6110 | |
| 6111 | /** |
Benjamin Franz | 77c94a9 | 2017-08-09 14:16:03 +0100 | [diff] [blame] | 6112 | * Flag used by {@link #createAndManageUser} to specificy that the newly created user should be |
| 6113 | * started in the background as part of the user creation. |
| 6114 | */ |
| 6115 | // TODO: Investigate solutions for the case where reboot happens before setup is completed. |
| 6116 | public static final int START_USER_IN_BACKGROUND = 0x0008; |
| 6117 | |
| 6118 | /** |
| 6119 | * @hide |
| 6120 | */ |
| 6121 | @IntDef( |
| 6122 | flag = true, |
| 6123 | prefix = {"SKIP_", "MAKE_USER_", "START_"}, |
| 6124 | value = {SKIP_SETUP_WIZARD, MAKE_USER_EPHEMERAL, MAKE_USER_DEMO, |
| 6125 | START_USER_IN_BACKGROUND} |
| 6126 | ) |
| 6127 | @Retention(RetentionPolicy.SOURCE) |
| 6128 | public @interface CreateAndManageUserFlags {} |
| 6129 | |
| 6130 | |
| 6131 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6132 | * Called by a device owner to create a user with the specified name and a given component of |
| 6133 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 6134 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 6135 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 6136 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6137 | * <p> |
| 6138 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 6139 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 6140 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 6141 | * on the new user. |
| 6142 | * <p> |
| 6143 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 6144 | * for the first time. Then the extras will be passed to the admin when onEnable is called. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6145 | * |
| 6146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6147 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6148 | * @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] | 6149 | * same package as admin, otherwise no user is created and an |
| 6150 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6151 | * @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] | 6152 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6153 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6154 | * @see UserHandle |
| 6155 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6156 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6157 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6158 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6159 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 6160 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6161 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
Benjamin Franz | 77c94a9 | 2017-08-09 14:16:03 +0100 | [diff] [blame] | 6162 | @CreateAndManageUserFlags int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6163 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6164 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6165 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6166 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6167 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6168 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6172 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 6173 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6174 | * |
| 6175 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6176 | * @param userHandle the user to remove. |
| 6177 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6178 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6179 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6180 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6181 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6182 | try { |
| 6183 | return mService.removeUser(admin, userHandle); |
| 6184 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6185 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6186 | } |
| 6187 | } |
| 6188 | |
| 6189 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6190 | * Called by a device owner to switch the specified user to the foreground. |
| 6191 | * |
| 6192 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6193 | * @param userHandle the user to switch to; null will switch to primary. |
| 6194 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6195 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6196 | * @see Intent#ACTION_USER_FOREGROUND |
| 6197 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6198 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6199 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6200 | try { |
| 6201 | return mService.switchUser(admin, userHandle); |
| 6202 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6203 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6204 | } |
| 6205 | } |
| 6206 | |
| 6207 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6208 | * Retrieves the application restrictions for a given target application running in the calling |
| 6209 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6210 | * <p> |
| 6211 | * 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] | 6212 | * application restrictions via {@link #setDelegatedScopes} with the |
| 6213 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6214 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6215 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 6216 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6217 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6218 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6219 | * @param packageName The name of the package to fetch restricted settings of. |
| 6220 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6221 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 6222 | * {@link Bundle} if no restrictions have been set. |
| 6223 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6224 | * @see #setDelegatedScopes |
| 6225 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6226 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6227 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6228 | public @NonNull Bundle getApplicationRestrictions( |
| 6229 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6230 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6231 | if (mService != null) { |
| 6232 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6233 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 6234 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6235 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6236 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6237 | } |
| 6238 | } |
| 6239 | return null; |
| 6240 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6241 | |
| 6242 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6243 | * 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] | 6244 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6245 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6246 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6247 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6248 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6249 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6250 | * for the list of keys. |
| 6251 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6252 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6253 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6254 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6255 | if (mService != null) { |
| 6256 | try { |
| 6257 | mService.setUserRestriction(admin, key, true); |
| 6258 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6259 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6260 | } |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6265 | * 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] | 6266 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6267 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6268 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6269 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6270 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6271 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6272 | * for the list of keys. |
| 6273 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6274 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6275 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6276 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6277 | if (mService != null) { |
| 6278 | try { |
| 6279 | mService.setUserRestriction(admin, key, false); |
| 6280 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6281 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6282 | } |
| 6283 | } |
| 6284 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 6285 | |
| 6286 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6287 | * Called by a profile or device owner to get user restrictions set with |
| 6288 | * {@link #addUserRestriction(ComponentName, String)}. |
| 6289 | * <p> |
| 6290 | * 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] | 6291 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6292 | * {@link UserManager#getUserRestrictions()}. |
| 6293 | * |
| 6294 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6295 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6296 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6297 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6298 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6299 | Bundle ret = null; |
| 6300 | if (mService != null) { |
| 6301 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 6302 | ret = mService.getUserRestrictions(admin); |
| 6303 | } catch (RemoteException e) { |
| 6304 | throw e.rethrowFromSystemServer(); |
| 6305 | } |
| 6306 | } |
| 6307 | return ret == null ? new Bundle() : ret; |
| 6308 | } |
| 6309 | |
| 6310 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6311 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 6312 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 6313 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 6314 | * was disabled by an admin, and include a link for more information. The default content of |
| 6315 | * the dialog can be changed by the restricting admin via |
| 6316 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 6317 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 6318 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 6319 | * user restriction from {@link UserManager}, e.g. |
| 6320 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
| 6321 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 6322 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 6323 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 6324 | */ |
| 6325 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 6326 | throwIfParentInstance("createAdminSupportIntent"); |
| 6327 | if (mService != null) { |
| 6328 | try { |
| 6329 | return mService.createAdminSupportIntent(restriction); |
| 6330 | } catch (RemoteException e) { |
| 6331 | throw e.rethrowFromSystemServer(); |
| 6332 | } |
| 6333 | } |
| 6334 | return null; |
| 6335 | } |
| 6336 | |
| 6337 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6338 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 6339 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 6340 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6341 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6342 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6343 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6344 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6345 | * @param packageName The name of the package to hide or unhide. |
| 6346 | * @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] | 6347 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6348 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6349 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6350 | * @see #setDelegatedScopes |
| 6351 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6352 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6353 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6354 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6355 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6356 | if (mService != null) { |
| 6357 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6358 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 6359 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6360 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6361 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6362 | } |
| 6363 | } |
| 6364 | return false; |
| 6365 | } |
| 6366 | |
| 6367 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6368 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 6369 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6370 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6371 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6372 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6373 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6374 | * @param packageName The name of the package to retrieve the hidden status of. |
| 6375 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6376 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6377 | * @see #setDelegatedScopes |
| 6378 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6379 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6380 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6381 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6382 | if (mService != null) { |
| 6383 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6384 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6385 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6386 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6387 | } |
| 6388 | } |
| 6389 | return false; |
| 6390 | } |
| 6391 | |
| 6392 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6393 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 6394 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6395 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6396 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6397 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6398 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6399 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6400 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6401 | * @see #setDelegatedScopes |
| 6402 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6403 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6404 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6405 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6406 | if (mService != null) { |
| 6407 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6408 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6409 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6410 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6411 | } |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6416 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 6417 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 6418 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6419 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6420 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6421 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6422 | * @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] | 6423 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6424 | * @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] | 6425 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6426 | * @see #setDelegatedScopes |
| 6427 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6429 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6430 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6431 | if (mService != null) { |
| 6432 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6433 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6434 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6435 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6436 | } |
| 6437 | } |
| 6438 | return 0; |
| 6439 | } |
| 6440 | |
| 6441 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 6442 | * Called by a device owner or profile owner to disable account management for a specific type |
| 6443 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6444 | * <p> |
| 6445 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 6446 | * exception will be thrown. |
| 6447 | * <p> |
| 6448 | * When account management is disabled for an account type, adding or removing an account of |
| 6449 | * that type will not be possible. |
| 6450 | * <p> |
| 6451 | * 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] | 6452 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 6453 | * management for a specific type is disabled. |
| 6454 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6455 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6456 | * @param accountType For which account management is disabled or enabled. |
| 6457 | * @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] | 6458 | * enabled (false). |
| 6459 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6460 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6461 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6462 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6463 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6464 | if (mService != null) { |
| 6465 | try { |
| 6466 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 6467 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6468 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6469 | } |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6474 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 6475 | * |
| 6476 | * <p> Account management can be disabled/enabled by calling |
| 6477 | * {@link #setAccountManagementDisabled}. |
| 6478 | * |
| 6479 | * @return a list of account types for which account management has been disabled. |
| 6480 | * |
| 6481 | * @see #setAccountManagementDisabled |
| 6482 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6483 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6484 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 6485 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6486 | } |
| 6487 | |
| 6488 | /** |
| 6489 | * @see #getAccountTypesWithManagementDisabled() |
| 6490 | * @hide |
| 6491 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6492 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6493 | if (mService != null) { |
| 6494 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6495 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6496 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6497 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6498 | } |
| 6499 | } |
| 6500 | |
| 6501 | return null; |
| 6502 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6503 | |
| 6504 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6505 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6506 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6507 | * 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] | 6508 | * 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] | 6509 | * package list results in locked tasks belonging to those packages to be finished. |
| 6510 | * <p> |
| 6511 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6512 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages |
| 6513 | * set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6514 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6515 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6516 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6517 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6518 | * an affiliated user or profile. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6519 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6520 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6521 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6522 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6523 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6524 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6525 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6526 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6527 | if (mService != null) { |
| 6528 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6529 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6530 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6531 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6532 | } |
| 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6537 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6538 | * |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6539 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6540 | * an affiliated user or profile. |
| 6541 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6542 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6543 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6544 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6545 | if (mService != null) { |
| 6546 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6547 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6548 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6549 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6550 | } |
| 6551 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6552 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | /** |
| 6556 | * This function lets the caller know whether the given component is allowed to start the |
| 6557 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6558 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6559 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6560 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6561 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6562 | if (mService != null) { |
| 6563 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6564 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6565 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6566 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6567 | } |
| 6568 | } |
| 6569 | return false; |
| 6570 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6571 | |
| 6572 | /** |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 6573 | * Sets which system features to enable for LockTask mode. |
| 6574 | * <p> |
| 6575 | * Feature flags set through this method will only take effect for the duration when the device |
| 6576 | * is in LockTask mode. If this method is not called, none of the features listed here will be |
| 6577 | * enabled. |
| 6578 | * <p> |
| 6579 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6580 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any features |
| 6581 | * set via this method will be cleared if the user becomes unaffiliated. |
| 6582 | * |
| 6583 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6584 | * @param flags Bitfield of feature flags: |
| 6585 | * {@link #LOCK_TASK_FEATURE_NONE} (default), |
| 6586 | * {@link #LOCK_TASK_FEATURE_SYSTEM_INFO}, |
| 6587 | * {@link #LOCK_TASK_FEATURE_NOTIFICATIONS}, |
| 6588 | * {@link #LOCK_TASK_FEATURE_HOME}, |
| 6589 | * {@link #LOCK_TASK_FEATURE_RECENTS}, |
| 6590 | * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS}, |
| 6591 | * {@link #LOCK_TASK_FEATURE_KEYGUARD} |
| 6592 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6593 | * an affiliated user or profile. |
| 6594 | */ |
| 6595 | public void setLockTaskFeatures(@NonNull ComponentName admin, @LockTaskFeature int flags) { |
| 6596 | throwIfParentInstance("setLockTaskFeatures"); |
| 6597 | if (mService != null) { |
| 6598 | try { |
| 6599 | mService.setLockTaskFeatures(admin, flags); |
| 6600 | } catch (RemoteException e) { |
| 6601 | throw e.rethrowFromSystemServer(); |
| 6602 | } |
| 6603 | } |
| 6604 | } |
| 6605 | |
| 6606 | /** |
| 6607 | * Gets which system features are enabled for LockTask mode. |
| 6608 | * |
| 6609 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6610 | * @return bitfield of flags. See {@link #setLockTaskFeatures(ComponentName, int)} for a list. |
| 6611 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6612 | * an affiliated user or profile. |
| 6613 | * @see #setLockTaskFeatures(ComponentName, int) |
| 6614 | */ |
| 6615 | public @LockTaskFeature int getLockTaskFeatures(@NonNull ComponentName admin) { |
| 6616 | throwIfParentInstance("getLockTaskFeatures"); |
| 6617 | if (mService != null) { |
| 6618 | try { |
| 6619 | return mService.getLockTaskFeatures(admin); |
| 6620 | } catch (RemoteException e) { |
| 6621 | throw e.rethrowFromSystemServer(); |
| 6622 | } |
| 6623 | } |
| 6624 | return 0; |
| 6625 | } |
| 6626 | |
| 6627 | /** |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6628 | * Called by device owners to update {@link android.provider.Settings.Global} settings. |
| 6629 | * Validation that the value of the setting is in the correct form for the setting type should |
| 6630 | * be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6631 | * <p> |
| 6632 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6633 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6634 | * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li> |
| 6635 | * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li> |
| 6636 | * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li> |
| 6637 | * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li> |
| 6638 | * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
| 6639 | * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li> |
| 6640 | * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only |
| 6641 | * 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] | 6642 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6643 | * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This |
| 6644 | * 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] | 6645 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6646 | * <p> |
| 6647 | * 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] | 6648 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6649 | * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6650 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6651 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6652 | * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 6653 | * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6654 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6655 | * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li> |
| 6656 | * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6657 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6658 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6659 | * |
| 6660 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6661 | * @param setting The name of the setting to update. |
| 6662 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6663 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6664 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6665 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6666 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6667 | if (mService != null) { |
| 6668 | try { |
| 6669 | mService.setGlobalSetting(admin, setting, value); |
| 6670 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6671 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6672 | } |
| 6673 | } |
| 6674 | } |
| 6675 | |
| 6676 | /** |
yuemingw | e43cdf7 | 2017-10-12 16:52:11 +0100 | [diff] [blame] | 6677 | * Called by device owner to set the system wall clock time. This only takes effect if called |
| 6678 | * when {@link android.provider.Settings.Global#AUTO_TIME} is 0, otherwise {@code false} will be |
| 6679 | * returned. |
| 6680 | * |
| 6681 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with |
| 6682 | * @param millis time in milliseconds since the Epoch |
| 6683 | * @return {@code true} if set time succeeded, {@code false} otherwise. |
| 6684 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6685 | */ |
| 6686 | public boolean setTime(@NonNull ComponentName admin, long millis) { |
| 6687 | throwIfParentInstance("setTime"); |
| 6688 | if (mService != null) { |
| 6689 | try { |
| 6690 | return mService.setTime(admin, millis); |
| 6691 | } catch (RemoteException e) { |
| 6692 | throw e.rethrowFromSystemServer(); |
| 6693 | } |
| 6694 | } |
| 6695 | return false; |
| 6696 | } |
| 6697 | |
| 6698 | /** |
| 6699 | * Called by device owner to set the system's persistent default time zone. This only takes |
| 6700 | * effect if called when {@link android.provider.Settings.Global#AUTO_TIME_ZONE} is 0, otherwise |
| 6701 | * {@code false} will be returned. |
| 6702 | * |
| 6703 | * @see android.app.AlarmManager#setTimeZone(String) |
| 6704 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with |
| 6705 | * @param timeZone one of the Olson ids from the list returned by |
| 6706 | * {@link java.util.TimeZone#getAvailableIDs} |
| 6707 | * @return {@code true} if set timezone succeeded, {@code false} otherwise. |
| 6708 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6709 | */ |
| 6710 | public boolean setTimeZone(@NonNull ComponentName admin, String timeZone) { |
| 6711 | throwIfParentInstance("setTimeZone"); |
| 6712 | if (mService != null) { |
| 6713 | try { |
| 6714 | return mService.setTimeZone(admin, timeZone); |
| 6715 | } catch (RemoteException e) { |
| 6716 | throw e.rethrowFromSystemServer(); |
| 6717 | } |
| 6718 | } |
| 6719 | return false; |
| 6720 | } |
| 6721 | |
| 6722 | /** |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6723 | * Called by profile or device owners to update {@link android.provider.Settings.Secure} |
| 6724 | * settings. Validation that the value of the setting is in the correct form for the setting |
| 6725 | * type should be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6726 | * <p> |
| 6727 | * 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] | 6728 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6729 | * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
| 6730 | * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6731 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6732 | * <p> |
| 6733 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6734 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6735 | * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6736 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6737 | * |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 6738 | * <strong>Note: Starting from Android O, apps should no longer call this method with the |
| 6739 | * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is |
| 6740 | * deprecated. Instead, device owners or profile owners should use the restriction |
| 6741 | * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
| 6742 | * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method |
| 6743 | * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, |
| 6744 | * an {@link UnsupportedOperationException} is thrown. |
| 6745 | * </strong> |
| 6746 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6747 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6748 | * @param setting The name of the setting to update. |
| 6749 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6750 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6751 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6752 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6753 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6754 | if (mService != null) { |
| 6755 | try { |
| 6756 | mService.setSecureSetting(admin, setting, value); |
| 6757 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6758 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6759 | } |
| 6760 | } |
| 6761 | } |
| 6762 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6763 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6764 | * Designates a specific service component as the provider for making permission requests of a |
| 6765 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6766 | * <p/> |
| 6767 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6768 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6769 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6770 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6771 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6772 | * provider previously assigned. |
| 6773 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6774 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6775 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6776 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6777 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6778 | if (mService != null) { |
| 6779 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6780 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6781 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6782 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6783 | } |
| 6784 | } |
| 6785 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6786 | |
| 6787 | /** |
| 6788 | * 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] | 6789 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6790 | * |
| 6791 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6792 | * @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] | 6793 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6794 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6795 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6796 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6797 | if (mService != null) { |
| 6798 | try { |
| 6799 | mService.setMasterVolumeMuted(admin, on); |
| 6800 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6801 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6802 | } |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | /** |
| 6807 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6808 | * |
| 6809 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6810 | * @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] | 6811 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6812 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6813 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6814 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6815 | if (mService != null) { |
| 6816 | try { |
| 6817 | return mService.isMasterVolumeMuted(admin); |
| 6818 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6819 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6820 | } |
| 6821 | } |
| 6822 | return false; |
| 6823 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6824 | |
| 6825 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6826 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6827 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6828 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6829 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6830 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6831 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6832 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6833 | * @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] | 6834 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6835 | * @see #setDelegatedScopes |
| 6836 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6837 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6838 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6839 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6840 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6841 | if (mService != null) { |
| 6842 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6843 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6844 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6845 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6846 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6847 | } |
| 6848 | } |
| 6849 | } |
| 6850 | |
| 6851 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6852 | * 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] | 6853 | * 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] | 6854 | * <p> |
| 6855 | * <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] | 6856 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6857 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6858 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6859 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6860 | * @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] | 6861 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6862 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6863 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6864 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6865 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6866 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6867 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6868 | if (mService != null) { |
| 6869 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6870 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6871 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6872 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6873 | } |
| 6874 | } |
| 6875 | return false; |
| 6876 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6877 | |
| 6878 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6879 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6880 | * package to be available in the parent profile. As a result the user will be able to add |
| 6881 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6882 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6883 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6884 | * <p> |
| 6885 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6886 | * |
| 6887 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6888 | * @param packageName The package from which widget providers are white-listed. |
| 6889 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6890 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6891 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6892 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6893 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6894 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6895 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6896 | if (mService != null) { |
| 6897 | try { |
| 6898 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6899 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6900 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6901 | } |
| 6902 | } |
| 6903 | return false; |
| 6904 | } |
| 6905 | |
| 6906 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6907 | * 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] | 6908 | * package to be available in the parent profile. For this method to take effect the package |
| 6909 | * should have been added via |
| 6910 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6911 | * <p> |
| 6912 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6913 | * |
| 6914 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6915 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6916 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6917 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6918 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6919 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6920 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6921 | public boolean removeCrossProfileWidgetProvider( |
| 6922 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6923 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6924 | if (mService != null) { |
| 6925 | try { |
| 6926 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6927 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6928 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6929 | } |
| 6930 | } |
| 6931 | return false; |
| 6932 | } |
| 6933 | |
| 6934 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6935 | * 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] | 6936 | * available in the parent profile. |
| 6937 | * |
| 6938 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6939 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6940 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6941 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6942 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6943 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6944 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6945 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6946 | if (mService != null) { |
| 6947 | try { |
| 6948 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6949 | if (providers != null) { |
| 6950 | return providers; |
| 6951 | } |
| 6952 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6953 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6954 | } |
| 6955 | } |
| 6956 | return Collections.emptyList(); |
| 6957 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6958 | |
| 6959 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6960 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6961 | * |
| 6962 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6963 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6964 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6965 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6966 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6967 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6968 | try { |
| 6969 | mService.setUserIcon(admin, icon); |
| 6970 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6971 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6972 | } |
| 6973 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6974 | |
| 6975 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6976 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6977 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6978 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6979 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6980 | * components in the device owner package can set system update policies and the most |
| 6981 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6982 | * @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] | 6983 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6984 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6985 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6986 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6987 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6988 | if (mService != null) { |
| 6989 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6990 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6991 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6992 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6993 | } |
| 6994 | } |
| 6995 | } |
| 6996 | |
| 6997 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6998 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6999 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7000 | * @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] | 7001 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7002 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7003 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7004 | if (mService != null) { |
| 7005 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 7006 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7007 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7008 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 7009 | } |
| 7010 | } |
| 7011 | return null; |
| 7012 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7013 | |
| 7014 | /** |
| 7015 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7016 | * <p> |
| 7017 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 7018 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 7019 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 7020 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7021 | * |
Benjamin Franz | 32a3bf3 | 2017-08-04 15:01:52 +0100 | [diff] [blame] | 7022 | * <p> |
Benjamin Franz | 64affcb | 2017-09-01 13:47:22 +0100 | [diff] [blame] | 7023 | * 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] | 7024 | * keyguard if it is currently shown. |
| 7025 | * |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7026 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7027 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7028 | * @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] | 7029 | * place. {@code true} otherwise. |
| 7030 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7031 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7032 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7033 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7034 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7035 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7036 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7037 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 7038 | } |
| 7039 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7040 | |
| 7041 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7042 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7043 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 7044 | * device. |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 7045 | * <p> |
| 7046 | * <strong>Note:</strong> This method has no effect for LockTask mode. The behavior of the |
| 7047 | * status bar in LockTask mode can be configured with |
| 7048 | * {@link #setLockTaskFeatures(ComponentName, int)}. Calls to this method when the device is in |
| 7049 | * LockTask mode will be registered, but will only take effect when the device leaves LockTask |
| 7050 | * mode. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7051 | * |
| 7052 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7053 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7054 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 7055 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7056 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7057 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7058 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7059 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 7060 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7061 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7062 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 7063 | } |
| 7064 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7065 | |
| 7066 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7067 | * Called by the system update service to notify device and profile owners of pending system |
| 7068 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7069 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7070 | * 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] | 7071 | * update is a security patch. Otherwise, use |
| 7072 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 7073 | * |
| 7074 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 7075 | * indicating when the current pending update was first available. {@code -1} if no |
| 7076 | * update is available. |
| 7077 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7078 | * @hide |
| 7079 | */ |
| 7080 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7081 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7082 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7083 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7084 | if (mService != null) { |
| 7085 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7086 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 7087 | } catch (RemoteException re) { |
| 7088 | throw re.rethrowFromSystemServer(); |
| 7089 | } |
| 7090 | } |
| 7091 | } |
| 7092 | |
| 7093 | /** |
| 7094 | * Called by the system update service to notify device and profile owners of pending system |
| 7095 | * updates. |
| 7096 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7097 | * This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7098 | * when it is known whether the pending system update is a security patch. |
| 7099 | * |
| 7100 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 7101 | * indicating when the current pending update was first available. {@code -1} if no |
| 7102 | * update is available. |
| 7103 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 7104 | * {@code false} if not. |
| 7105 | * @see #notifyPendingSystemUpdate(long) |
| 7106 | * @hide |
| 7107 | */ |
| 7108 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7109 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 7110 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 7111 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 7112 | if (mService != null) { |
| 7113 | try { |
| 7114 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 7115 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7116 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7117 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 7118 | } |
| 7119 | } |
| 7120 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 7121 | |
| 7122 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 7123 | * Called by device or profile owners to get information about a pending system update. |
| 7124 | * |
| 7125 | * @param admin Which profile or device owner this request is associated with. |
| 7126 | * @return Information about a pending system update or {@code null} if no update pending. |
| 7127 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 7128 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 7129 | */ |
| 7130 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 7131 | throwIfParentInstance("getPendingSystemUpdate"); |
| 7132 | try { |
| 7133 | return mService.getPendingSystemUpdate(admin); |
| 7134 | } catch (RemoteException re) { |
| 7135 | throw re.rethrowFromSystemServer(); |
| 7136 | } |
| 7137 | } |
| 7138 | |
| 7139 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7140 | * Set the default response for future runtime permission requests by applications. This |
| 7141 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 7142 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 7143 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 7144 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 7145 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 7146 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 7147 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7148 | * <p/> |
| 7149 | * 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] | 7150 | * 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] | 7151 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7152 | * @param admin Which profile or device owner this request is associated with. |
| 7153 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7154 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 7155 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 7156 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7157 | * @see #setDelegatedScopes |
| 7158 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7159 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7160 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7161 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7162 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7163 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7164 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7165 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7166 | } |
| 7167 | } |
| 7168 | |
| 7169 | /** |
| 7170 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 7171 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7172 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7173 | * @param admin Which profile or device owner this request is associated with. |
| 7174 | * @return the current policy for future permission requests. |
| 7175 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 7176 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7177 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7178 | try { |
| 7179 | return mService.getPermissionPolicy(admin); |
| 7180 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7181 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7186 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 7187 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 7188 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 7189 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 7190 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 7191 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7192 | * by a profile owner, device owner, or a delegate given the |
| 7193 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7194 | * <p/> |
| 7195 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 7196 | * the permission. It retains the previous grant, if any. |
| 7197 | * <p/> |
| 7198 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 7199 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 7200 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7201 | * @param admin Which profile or device owner this request is associated with. |
| 7202 | * @param packageName The application to grant or revoke a permission to. |
| 7203 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7204 | * @param grantState The permission grant state which is one of |
| 7205 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 7206 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 7207 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7208 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 7209 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 7210 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 7211 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7212 | * @see #setDelegatedScopes |
| 7213 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7214 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 7215 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 7216 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7217 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7218 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7219 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 7220 | permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7221 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7222 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 7223 | } |
| 7224 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7225 | |
| 7226 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7227 | * Returns the current grant state of a runtime permission for a specific application. This |
| 7228 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 7229 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7230 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7231 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 7232 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7233 | * @param packageName The application to check the grant state for. |
| 7234 | * @param permission The permission to check for. |
| 7235 | * @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] | 7236 | * has not set a grant state, the return value is |
| 7237 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 7238 | * permission is currently granted for the package. |
| 7239 | * <p/> |
| 7240 | * If a grant state was set by the profile or device owner, then the return value will |
| 7241 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 7242 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 7243 | * currently denied or granted. |
| 7244 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7245 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 7246 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7247 | * @see #setDelegatedScopes |
| 7248 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7249 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 7250 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7251 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7252 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7253 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7254 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 7255 | permission); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7256 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7257 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7258 | } |
| 7259 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7260 | |
| 7261 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7262 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 7263 | * or device, setting itself as the device or profile owner. |
| 7264 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7265 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 7266 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7267 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7268 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 7269 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7270 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7271 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7272 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7273 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7274 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7275 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7276 | } |
| 7277 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7278 | |
| 7279 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7280 | * Checks whether it is possible to initiate provisioning a managed device, |
| 7281 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7282 | * |
| 7283 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 7284 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 7285 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 7286 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7287 | * @param packageName The package of the component that would be set as device, user, or profile |
| 7288 | * owner. |
| 7289 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7290 | * @hide |
| 7291 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7292 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 7293 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7294 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7295 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7296 | } catch (RemoteException re) { |
| 7297 | throw re.rethrowFromSystemServer(); |
| 7298 | } |
| 7299 | } |
| 7300 | |
| 7301 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7302 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 7303 | * 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] | 7304 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7305 | * @param admin Which profile owner this request is associated with. |
| 7306 | * @return if this user is a managed profile of another user. |
| 7307 | */ |
| 7308 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7309 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7310 | try { |
| 7311 | return mService.isManagedProfile(admin); |
| 7312 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7313 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7314 | } |
| 7315 | } |
| 7316 | |
| 7317 | /** |
| 7318 | * @hide |
| 7319 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 7320 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 7321 | * @param admin Which device owner this request is associated with. |
| 7322 | * @return if this user is a system-only user. |
| 7323 | */ |
| 7324 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 7325 | try { |
| 7326 | return mService.isSystemOnlyUser(admin); |
| 7327 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7328 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7329 | } |
| 7330 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7331 | |
| 7332 | /** |
| 7333 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 7334 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7335 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7336 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 7337 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 7338 | * <p> |
| 7339 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 7340 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7341 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7342 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7343 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7344 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7345 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7346 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7347 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7348 | } |
| 7349 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7350 | |
| 7351 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7352 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 7353 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7354 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7355 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7356 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7357 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7358 | */ |
| 7359 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7360 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7361 | try { |
| 7362 | mService.reboot(admin); |
| 7363 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7364 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7365 | } |
| 7366 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7367 | |
| 7368 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7369 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 7370 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 7371 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 7372 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 7373 | * truncated. |
| 7374 | * <p> |
| 7375 | * 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] | 7376 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7377 | * and set a new version of this string accordingly. |
| 7378 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7379 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7380 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7381 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 7382 | * existing message. |
| 7383 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7384 | */ |
| 7385 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7386 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7387 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7388 | if (mService != null) { |
| 7389 | try { |
| 7390 | mService.setShortSupportMessage(admin, message); |
| 7391 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7392 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7393 | } |
| 7394 | } |
| 7395 | } |
| 7396 | |
| 7397 | /** |
| 7398 | * Called by a device admin to get the short support message. |
| 7399 | * |
| 7400 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7401 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 7402 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7403 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7404 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7405 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7406 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7407 | if (mService != null) { |
| 7408 | try { |
| 7409 | return mService.getShortSupportMessage(admin); |
| 7410 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7411 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7412 | } |
| 7413 | } |
| 7414 | return null; |
| 7415 | } |
| 7416 | |
| 7417 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7418 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 7419 | * in the device administators settings screen. |
| 7420 | * <p> |
| 7421 | * 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] | 7422 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7423 | * and set a new version of this string accordingly. |
| 7424 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7425 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7426 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7427 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 7428 | * existing message. |
| 7429 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7430 | */ |
| 7431 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7432 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7433 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7434 | if (mService != null) { |
| 7435 | try { |
| 7436 | mService.setLongSupportMessage(admin, message); |
| 7437 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7438 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7439 | } |
| 7440 | } |
| 7441 | } |
| 7442 | |
| 7443 | /** |
| 7444 | * Called by a device admin to get the long support message. |
| 7445 | * |
| 7446 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7447 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 7448 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7449 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7450 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7451 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7452 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7453 | if (mService != null) { |
| 7454 | try { |
| 7455 | return mService.getLongSupportMessage(admin); |
| 7456 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7457 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7458 | } |
| 7459 | } |
| 7460 | return null; |
| 7461 | } |
| 7462 | |
| 7463 | /** |
| 7464 | * Called by the system to get the short support message. |
| 7465 | * |
| 7466 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7467 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7468 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7469 | * |
| 7470 | * @hide |
| 7471 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7472 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7473 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7474 | if (mService != null) { |
| 7475 | try { |
| 7476 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 7477 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7478 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7479 | } |
| 7480 | } |
| 7481 | return null; |
| 7482 | } |
| 7483 | |
| 7484 | |
| 7485 | /** |
| 7486 | * Called by the system to get the long support message. |
| 7487 | * |
| 7488 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7489 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7490 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7491 | * |
| 7492 | * @hide |
| 7493 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7494 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 7495 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7496 | if (mService != null) { |
| 7497 | try { |
| 7498 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 7499 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7500 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7501 | } |
| 7502 | } |
| 7503 | return null; |
| 7504 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7505 | |
| 7506 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 7507 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 7508 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7509 | * |
| 7510 | * <p>The following methods are supported for the parent instance, all other methods will |
| 7511 | * throw a SecurityException when called on the parent instance: |
| 7512 | * <ul> |
| 7513 | * <li>{@link #getPasswordQuality}</li> |
| 7514 | * <li>{@link #setPasswordQuality}</li> |
| 7515 | * <li>{@link #getPasswordMinimumLength}</li> |
| 7516 | * <li>{@link #setPasswordMinimumLength}</li> |
| 7517 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 7518 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 7519 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 7520 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 7521 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 7522 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 7523 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 7524 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 7525 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 7526 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 7527 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 7528 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 7529 | * <li>{@link #getPasswordHistoryLength}</li> |
| 7530 | * <li>{@link #setPasswordHistoryLength}</li> |
| 7531 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 7532 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 7533 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 7534 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7535 | * <li>{@link #isActivePasswordSufficient}</li> |
| 7536 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 7537 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 7538 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 7539 | * <li>{@link #getMaximumTimeToLock}</li> |
| 7540 | * <li>{@link #setMaximumTimeToLock}</li> |
| 7541 | * <li>{@link #lockNow}</li> |
| 7542 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 7543 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 7544 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 7545 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 7546 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 7547 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7548 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7549 | * |
| 7550 | * @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] | 7551 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7552 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7553 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7554 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7555 | try { |
| 7556 | if (!mService.isManagedProfile(admin)) { |
| 7557 | throw new SecurityException("The current user does not have a parent profile."); |
| 7558 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7559 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7560 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7561 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7562 | } |
| 7563 | } |
| 7564 | |
| 7565 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7566 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7567 | * |
| 7568 | * <p> Security logs contain various information intended for security auditing purposes. |
| 7569 | * See {@link SecurityEvent} for details. |
| 7570 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7571 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 7572 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7573 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7574 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7575 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7576 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7577 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7578 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7579 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7580 | * @see #retrieveSecurityLogs |
| 7581 | */ |
| 7582 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7583 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7584 | try { |
| 7585 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 7586 | } catch (RemoteException re) { |
| 7587 | throw re.rethrowFromSystemServer(); |
| 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7592 | * Return whether security logging is enabled or not by the device owner. |
| 7593 | * |
| 7594 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 7595 | * thrown. |
| 7596 | * |
| 7597 | * @param admin Which device owner this request is associated with. |
| 7598 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 7599 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7600 | */ |
Bartosz Fabianowski | 0ec0000 | 2017-03-24 14:22:24 +0100 | [diff] [blame] | 7601 | public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7602 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7603 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7604 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7605 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7606 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7607 | } |
| 7608 | } |
| 7609 | |
| 7610 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7611 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 7612 | * this API after device boots. |
| 7613 | * |
| 7614 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 7615 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 7616 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7617 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7618 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7619 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7620 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7621 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7622 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 7623 | * 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] | 7624 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7625 | * profile or secondary user that is not affiliated with the device owner user. |
| 7626 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7627 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7628 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7629 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7630 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7631 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7632 | if (list != null) { |
| 7633 | return list.getList(); |
| 7634 | } else { |
| 7635 | // Rate limit exceeded. |
| 7636 | return null; |
| 7637 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7638 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7639 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7640 | } |
| 7641 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7642 | |
| 7643 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7644 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7645 | * profile. |
| 7646 | * |
| 7647 | * @hide |
| 7648 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7649 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7650 | mContext.checkSelfPermission( |
| 7651 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7652 | if (!uInfo.isManagedProfile()) { |
| 7653 | throw new SecurityException("The user " + uInfo.id |
| 7654 | + " does not have a parent profile."); |
| 7655 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7656 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7657 | } |
| 7658 | |
| 7659 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7660 | * 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] | 7661 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7662 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7663 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7664 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7665 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7666 | * |
| 7667 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7668 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7669 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7670 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7671 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7672 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7673 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7674 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7675 | * profile or secondary user that is not affiliated with the device owner user. |
| 7676 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7677 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7678 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7679 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7680 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7681 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7682 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7683 | if (list != null) { |
| 7684 | return list.getList(); |
| 7685 | } else { |
| 7686 | return null; |
| 7687 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7688 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7689 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7690 | } |
| 7691 | } |
| 7692 | |
| 7693 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7694 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7695 | * 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] | 7696 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7697 | * <p> |
| 7698 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7699 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7700 | * |
| 7701 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7702 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7703 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7704 | */ |
| 7705 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7706 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7707 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7708 | // always enforce alpha channel to have 100% opacity |
| 7709 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7710 | mService.setOrganizationColor(admin, color); |
| 7711 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7712 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7713 | } |
| 7714 | } |
| 7715 | |
| 7716 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7717 | * @hide |
| 7718 | * |
| 7719 | * Sets the color used for customization. |
| 7720 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7721 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7722 | * @param userId which user to set the color to. |
| 7723 | * @RequiresPermission(allOf = { |
| 7724 | * Manifest.permission.MANAGE_USERS, |
| 7725 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7726 | */ |
| 7727 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7728 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7729 | // always enforce alpha channel to have 100% opacity |
| 7730 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7731 | mService.setOrganizationColorForUser(color, userId); |
| 7732 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7733 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7734 | } |
| 7735 | } |
| 7736 | |
| 7737 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7738 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7739 | * This color is used as background color of the confirm credentials screen for that user. |
| 7740 | * |
| 7741 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7742 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7743 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7744 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7745 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7746 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7747 | try { |
| 7748 | return mService.getOrganizationColor(admin); |
| 7749 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7750 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7751 | } |
| 7752 | } |
| 7753 | |
| 7754 | /** |
| 7755 | * @hide |
| 7756 | * Retrieve the customization color for a given user. |
| 7757 | * |
| 7758 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7759 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7760 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7761 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7762 | try { |
| 7763 | return mService.getOrganizationColorForUser(userHandle); |
| 7764 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7765 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7766 | } |
| 7767 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7768 | |
| 7769 | /** |
Wen ZHANG | 2be4cfc | 2017-09-21 18:29:43 +0100 | [diff] [blame] | 7770 | * Called by the device owner (since API 26) or profile owner (since API 24) to set the name of |
| 7771 | * the organization under management. |
| 7772 | * |
| 7773 | * <p>If the organization name needs to be localized, it is the responsibility of the {@link |
| 7774 | * DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast and set |
| 7775 | * a new version of this string accordingly. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7776 | * |
| 7777 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7778 | * @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] | 7779 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7780 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7781 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7782 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7783 | try { |
| 7784 | mService.setOrganizationName(admin, title); |
| 7785 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7786 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7787 | } |
| 7788 | } |
| 7789 | |
| 7790 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7791 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7792 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7793 | * |
| 7794 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7795 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7796 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7797 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7798 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7799 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7800 | try { |
| 7801 | return mService.getOrganizationName(admin); |
| 7802 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7803 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7808 | * Called by the system to retrieve the name of the organization managing the device. |
| 7809 | * |
| 7810 | * @return The organization name or {@code null} if none is set. |
| 7811 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7812 | * MANAGE_USERS permission and is not the system. |
| 7813 | * |
| 7814 | * @hide |
| 7815 | */ |
| 7816 | @SystemApi |
| 7817 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 7818 | @SuppressLint("Doclava125") |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7819 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7820 | try { |
| 7821 | return mService.getDeviceOwnerOrganizationName(); |
| 7822 | } catch (RemoteException re) { |
| 7823 | throw re.rethrowFromSystemServer(); |
| 7824 | } |
| 7825 | } |
| 7826 | |
| 7827 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7828 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7829 | * |
| 7830 | * @param userHandle The user id of the user we're interested in. |
| 7831 | * @return The organization name or {@code null} if none is set. |
| 7832 | * |
| 7833 | * @hide |
| 7834 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7835 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7836 | try { |
| 7837 | return mService.getOrganizationNameForUser(userHandle); |
| 7838 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7839 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7840 | } |
| 7841 | } |
| 7842 | |
| 7843 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7844 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7845 | * return {@link #STATE_USER_UNMANAGED} |
| 7846 | * @hide |
| 7847 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7848 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7849 | @UserProvisioningState |
| 7850 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7851 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7852 | if (mService != null) { |
| 7853 | try { |
| 7854 | return mService.getUserProvisioningState(); |
| 7855 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7856 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7857 | } |
| 7858 | } |
| 7859 | return STATE_USER_UNMANAGED; |
| 7860 | } |
| 7861 | |
| 7862 | /** |
| 7863 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7864 | * |
| 7865 | * @param state to store |
| 7866 | * @param userHandle for user |
| 7867 | * @hide |
| 7868 | */ |
| 7869 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7870 | if (mService != null) { |
| 7871 | try { |
| 7872 | mService.setUserProvisioningState(state, userHandle); |
| 7873 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7874 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7875 | } |
| 7876 | } |
| 7877 | } |
| 7878 | |
| 7879 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7880 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7881 | * 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] | 7882 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7883 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7884 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7885 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7886 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7887 | * created. |
| 7888 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7889 | * @param admin Which profile or device owner this request is associated with. |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7890 | * @param ids A set of opaque non-empty affiliation ids. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7891 | * |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7892 | * @throws IllegalArgumentException if {@code ids} is null or contains an empty string. |
| 7893 | */ |
| 7894 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) { |
| 7895 | throwIfParentInstance("setAffiliationIds"); |
| 7896 | if (ids == null) { |
| 7897 | throw new IllegalArgumentException("ids must not be null"); |
| 7898 | } |
| 7899 | try { |
| 7900 | mService.setAffiliationIds(admin, new ArrayList<>(ids)); |
| 7901 | } catch (RemoteException e) { |
| 7902 | throw e.rethrowFromSystemServer(); |
| 7903 | } |
| 7904 | } |
| 7905 | |
| 7906 | /** |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7907 | * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7908 | * empty set if none have been set. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7909 | */ |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7910 | public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) { |
Tony Mak | 62cf586 | 2017-05-02 13:50:18 +0100 | [diff] [blame] | 7911 | throwIfParentInstance("getAffiliationIds"); |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7912 | try { |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7913 | return new ArraySet<>(mService.getAffiliationIds(admin)); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7914 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7915 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7916 | } |
| 7917 | } |
| 7918 | |
| 7919 | /** |
| 7920 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7921 | * Returns whether this user/profile is affiliated with the device. |
| 7922 | * <p> |
| 7923 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7924 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7925 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7926 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7927 | */ |
| 7928 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7929 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7930 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7931 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7932 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7933 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7934 | } |
| 7935 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7936 | |
| 7937 | /** |
| 7938 | * @hide |
| 7939 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7940 | * to be started |
| 7941 | * @param packageName the package to check for |
| 7942 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7943 | */ |
| 7944 | public boolean isUninstallInQueue(String packageName) { |
| 7945 | try { |
| 7946 | return mService.isUninstallInQueue(packageName); |
| 7947 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7948 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7949 | } |
| 7950 | } |
| 7951 | |
| 7952 | /** |
| 7953 | * @hide |
| 7954 | * @param packageName the package containing active DAs to be uninstalled |
| 7955 | */ |
| 7956 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7957 | try { |
| 7958 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7959 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7960 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7961 | } |
| 7962 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7963 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7964 | /** |
| 7965 | * @hide |
| 7966 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7967 | * If the admin is a profile owner or device owner it will still be removed. |
| 7968 | * |
| 7969 | * @param userHandle user id to remove the admin for. |
| 7970 | * @param admin The administration compononent to remove. |
| 7971 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7972 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7973 | */ |
| 7974 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7975 | try { |
| 7976 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7977 | } catch (RemoteException re) { |
| 7978 | throw re.rethrowFromSystemServer(); |
| 7979 | } |
| 7980 | } |
| 7981 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7982 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7983 | * Returns whether the device has been provisioned. |
| 7984 | * |
| 7985 | * <p>Not for use by third-party applications. |
| 7986 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7987 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7988 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7989 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7990 | public boolean isDeviceProvisioned() { |
| 7991 | try { |
| 7992 | return mService.isDeviceProvisioned(); |
| 7993 | } catch (RemoteException re) { |
| 7994 | throw re.rethrowFromSystemServer(); |
| 7995 | } |
| 7996 | } |
| 7997 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7998 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7999 | * Writes that the provisioning configuration has been applied. |
| 8000 | * |
| 8001 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 8002 | * permission. |
| 8003 | * |
| 8004 | * <p>Not for use by third-party applications. |
| 8005 | * |
| 8006 | * @hide |
| 8007 | */ |
| 8008 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 8009 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8010 | public void setDeviceProvisioningConfigApplied() { |
| 8011 | try { |
| 8012 | mService.setDeviceProvisioningConfigApplied(); |
| 8013 | } catch (RemoteException re) { |
| 8014 | throw re.rethrowFromSystemServer(); |
| 8015 | } |
| 8016 | } |
| 8017 | |
| 8018 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8019 | * Returns whether the provisioning configuration has been applied. |
| 8020 | * |
| 8021 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 8022 | * |
| 8023 | * <p>Not for use by third-party applications. |
| 8024 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8025 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8026 | * |
| 8027 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8028 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 8029 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 8030 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 8031 | public boolean isDeviceProvisioningConfigApplied() { |
| 8032 | try { |
| 8033 | return mService.isDeviceProvisioningConfigApplied(); |
| 8034 | } catch (RemoteException re) { |
| 8035 | throw re.rethrowFromSystemServer(); |
| 8036 | } |
| 8037 | } |
| 8038 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 8039 | /** |
| 8040 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 8041 | * Force update user setup completed status. This API has no effect on user build. |
| 8042 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 8043 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 8044 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 8045 | */ |
| 8046 | public void forceUpdateUserSetupComplete() { |
| 8047 | try { |
| 8048 | mService.forceUpdateUserSetupComplete(); |
| 8049 | } catch (RemoteException re) { |
| 8050 | throw re.rethrowFromSystemServer(); |
| 8051 | } |
| 8052 | } |
| 8053 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 8054 | private void throwIfParentInstance(String functionName) { |
| 8055 | if (mParentInstance) { |
| 8056 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 8057 | } |
| 8058 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8059 | |
| 8060 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8061 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8062 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8063 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 8064 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8065 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8066 | * <p> Backup service is off by default when device owner is present. |
| 8067 | * |
Rubin Xu | 0367f07 | 2017-04-24 20:17:16 +0100 | [diff] [blame] | 8068 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8069 | * @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] | 8070 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8071 | */ |
| 8072 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 8073 | throwIfParentInstance("setBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8074 | try { |
| 8075 | mService.setBackupServiceEnabled(admin, enabled); |
| 8076 | } catch (RemoteException re) { |
| 8077 | throw re.rethrowFromSystemServer(); |
| 8078 | } |
| 8079 | } |
| 8080 | |
| 8081 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8082 | * Return whether the backup service is enabled by the device owner. |
| 8083 | * |
| 8084 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 8085 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8086 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 8087 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8088 | */ |
| 8089 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 8090 | throwIfParentInstance("isBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 8091 | try { |
| 8092 | return mService.isBackupServiceEnabled(admin); |
| 8093 | } catch (RemoteException re) { |
| 8094 | throw re.rethrowFromSystemServer(); |
| 8095 | } |
| 8096 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8097 | |
| 8098 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8099 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8100 | * |
Robin Lee | a40a2fb | 2017-02-08 17:07:06 +0000 | [diff] [blame] | 8101 | * <p> Network logs contain DNS lookup and connect() library call events. The following library |
| 8102 | * functions are recorded while network logging is active: |
| 8103 | * <ul> |
| 8104 | * <li>{@code getaddrinfo()}</li> |
| 8105 | * <li>{@code gethostbyname()}</li> |
| 8106 | * <li>{@code connect()}</li> |
| 8107 | * </ul> |
| 8108 | * |
| 8109 | * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use |
| 8110 | * full system call logging; event reporting is enabled by default for all processes but not |
| 8111 | * strongly enforced. |
| 8112 | * Events from applications using alternative implementations of libc, making direct kernel |
| 8113 | * calls, or deliberately obfuscating traffic may not be recorded. |
| 8114 | * |
| 8115 | * <p> Some common network events may not be reported. For example: |
| 8116 | * <ul> |
| 8117 | * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use |
| 8118 | * an alternative system for name resolution, and so avoid calling |
| 8119 | * {@code getaddrinfo()} or {@code gethostbyname}.</li> |
| 8120 | * <li>Applications may use datagram sockets for performance reasons, for example |
| 8121 | * for a game client. Calling {@code connect()} is unnecessary for this kind of |
| 8122 | * socket, so it will not trigger a network event.</li> |
| 8123 | * </ul> |
| 8124 | * |
| 8125 | * <p> It is possible to directly intercept layer 3 traffic leaving the device using an |
| 8126 | * always-on VPN service. |
| 8127 | * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} |
| 8128 | * and {@link android.net.VpnService} for details. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8129 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8130 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 8131 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 8132 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 8133 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 8134 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 8135 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8136 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8137 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8138 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 8139 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8140 | */ |
| 8141 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 8142 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 8143 | try { |
| 8144 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 8145 | } catch (RemoteException re) { |
| 8146 | throw re.rethrowFromSystemServer(); |
| 8147 | } |
| 8148 | } |
| 8149 | |
| 8150 | /** |
| 8151 | * Return whether network logging is enabled by a device owner. |
| 8152 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 8153 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 8154 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8155 | * @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] | 8156 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 8157 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8158 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 8159 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 8160 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 8161 | try { |
| 8162 | return mService.isNetworkLoggingEnabled(admin); |
| 8163 | } catch (RemoteException re) { |
| 8164 | throw re.rethrowFromSystemServer(); |
| 8165 | } |
| 8166 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 8167 | |
| 8168 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 8169 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 8170 | * A device owner has to provide a batchToken provided as part of |
| 8171 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 8172 | * 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] | 8173 | * |
| 8174 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 8175 | * |
| 8176 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 8177 | * |
| 8178 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 8179 | * after the device device owner has been notified via |
| 8180 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 8181 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8182 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 8183 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 8184 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 8185 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 8186 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 8187 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 8188 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 8189 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 8190 | * @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] | 8191 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 8192 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 8193 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 8194 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 8195 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 8196 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 8197 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 8198 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 8199 | throwIfParentInstance("retrieveNetworkLogs"); |
| 8200 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 8201 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 8202 | } catch (RemoteException re) { |
| 8203 | throw re.rethrowFromSystemServer(); |
| 8204 | } |
| 8205 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8206 | |
| 8207 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 8208 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 8209 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8210 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 8211 | * <p> |
Tony Mak | eda0a9a | 2017-04-25 12:07:14 +0100 | [diff] [blame] | 8212 | * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
| 8213 | * Note that the {@link Context} used to obtain this |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8214 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 8215 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8216 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8217 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8218 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 8219 | * explicit component name or a package name to match an |
| 8220 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 8221 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 8222 | * 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] | 8223 | * @param flags Operation options for the binding operation. See |
| 8224 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8225 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 8226 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 8227 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8228 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 8229 | * {@code false} is returned if the connection is not made and you will not |
| 8230 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8231 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8232 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8233 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8234 | */ |
| 8235 | public boolean bindDeviceAdminServiceAsUser( |
| 8236 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 8237 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 8238 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 8239 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 8240 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 8241 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 8242 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8243 | serviceIntent.prepareToLeaveProcess(mContext); |
| 8244 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 8245 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 8246 | sd, flags, targetUser.getIdentifier()); |
| 8247 | } catch (RemoteException re) { |
| 8248 | throw re.rethrowFromSystemServer(); |
| 8249 | } |
| 8250 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8251 | |
| 8252 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8253 | * Returns the list of target users that the calling device or profile owner can use when |
| 8254 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 8255 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 8256 | * 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] | 8257 | * <ul> |
| 8258 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 8259 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8260 | * </ul> |
| 8261 | */ |
| 8262 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 8263 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 8264 | try { |
| 8265 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 8266 | } catch (RemoteException re) { |
| 8267 | throw re.rethrowFromSystemServer(); |
| 8268 | } |
| 8269 | } |
| 8270 | |
| 8271 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8272 | * Called by the system to get the time at which the device owner last retrieved security |
| 8273 | * logging entries. |
| 8274 | * |
| 8275 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 8276 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8277 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8278 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8279 | * |
| 8280 | * @hide |
| 8281 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8282 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8283 | public long getLastSecurityLogRetrievalTime() { |
| 8284 | try { |
| 8285 | return mService.getLastSecurityLogRetrievalTime(); |
| 8286 | } catch (RemoteException re) { |
| 8287 | throw re.rethrowFromSystemServer(); |
| 8288 | } |
| 8289 | } |
| 8290 | |
| 8291 | /** |
| 8292 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 8293 | * |
| 8294 | * @return the time at which the device owner most recently requested a bug report, in |
| 8295 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8296 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8297 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8298 | * |
| 8299 | * @hide |
| 8300 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8301 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8302 | public long getLastBugReportRequestTime() { |
| 8303 | try { |
| 8304 | return mService.getLastBugReportRequestTime(); |
| 8305 | } catch (RemoteException re) { |
| 8306 | throw re.rethrowFromSystemServer(); |
| 8307 | } |
| 8308 | } |
| 8309 | |
| 8310 | /** |
| 8311 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 8312 | * events. |
| 8313 | * |
| 8314 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 8315 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8316 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8317 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8318 | * |
| 8319 | * @hide |
| 8320 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8321 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8322 | public long getLastNetworkLogRetrievalTime() { |
| 8323 | try { |
| 8324 | return mService.getLastNetworkLogRetrievalTime(); |
| 8325 | } catch (RemoteException re) { |
| 8326 | throw re.rethrowFromSystemServer(); |
| 8327 | } |
| 8328 | } |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8329 | |
| 8330 | /** |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8331 | * Called by the system to find out whether the current user's IME was set by the device/profile |
| 8332 | * owner or the user. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8333 | * |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8334 | * @return {@code true} if the user's IME was set by the device or profile owner, {@code false} |
| 8335 | * otherwise. |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8336 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8337 | * |
| 8338 | * @hide |
| 8339 | */ |
| 8340 | @TestApi |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8341 | public boolean isCurrentInputMethodSetByOwner() { |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8342 | try { |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8343 | return mService.isCurrentInputMethodSetByOwner(); |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8344 | } catch (RemoteException re) { |
| 8345 | throw re.rethrowFromSystemServer(); |
| 8346 | } |
| 8347 | } |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8348 | |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8349 | /** |
| 8350 | * Called by the system to get a list of CA certificates that were installed by the device or |
| 8351 | * profile owner. |
| 8352 | * |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8353 | * <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] | 8354 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 8355 | * |
| 8356 | * @param user The user for whom to retrieve information. |
| 8357 | * @return list of aliases identifying CA certificates installed by the device or profile owner |
| 8358 | * @throws SecurityException if the caller does not have permission to retrieve information |
| 8359 | * about the given user's CA certificates. |
| 8360 | * |
| 8361 | * @hide |
| 8362 | */ |
| 8363 | @TestApi |
| 8364 | public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) { |
| 8365 | try { |
| 8366 | return mService.getOwnerInstalledCaCerts(user).getList(); |
| 8367 | } catch (RemoteException re) { |
| 8368 | throw re.rethrowFromSystemServer(); |
| 8369 | } |
| 8370 | } |
Benjamin Franz | a77e357 | 2017-06-23 12:01:44 +0100 | [diff] [blame] | 8371 | |
| 8372 | /** |
| 8373 | * Called by the device owner or profile owner to clear application user data of a given |
| 8374 | * package. The behaviour of this is equivalent to the target application calling |
| 8375 | * {@link android.app.ActivityManager#clearApplicationUserData()}. |
| 8376 | * |
| 8377 | * <p><strong>Note:</strong> an application can store data outside of its application data, e.g. |
| 8378 | * external storage or user dictionary. This data will not be wiped by calling this API. |
| 8379 | * |
| 8380 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 8381 | * @param packageName The name of the package which will have its user data wiped. |
| 8382 | * @param listener A callback object that will inform the caller when the clearing is done. |
| 8383 | * @param handler The handler indicating the thread on which the listener should be invoked. |
| 8384 | * @throws SecurityException if the caller is not the device owner/profile owner. |
| 8385 | * @return whether the clearing succeeded. |
| 8386 | */ |
| 8387 | public boolean clearApplicationUserData(@NonNull ComponentName admin, |
| 8388 | @NonNull String packageName, @NonNull OnClearApplicationUserDataListener listener, |
| 8389 | @NonNull Handler handler) { |
| 8390 | throwIfParentInstance("clearAppData"); |
| 8391 | try { |
| 8392 | return mService.clearApplicationUserData(admin, packageName, |
| 8393 | new IPackageDataObserver.Stub() { |
| 8394 | public void onRemoveCompleted(String pkg, boolean succeeded) { |
| 8395 | handler.post(() -> |
| 8396 | listener.onApplicationUserDataCleared(pkg, succeeded)); |
| 8397 | } |
| 8398 | }); |
| 8399 | } catch (RemoteException re) { |
| 8400 | throw re.rethrowFromSystemServer(); |
| 8401 | } |
| 8402 | } |
| 8403 | |
| 8404 | /** |
| 8405 | * Callback used in {@link #clearApplicationUserData} |
| 8406 | * to indicate that the clearing of an application's user data is done. |
| 8407 | */ |
| 8408 | public interface OnClearApplicationUserDataListener { |
| 8409 | /** |
| 8410 | * Method invoked when clearing the application user data has completed. |
| 8411 | * |
| 8412 | * @param packageName The name of the package which had its user data cleared. |
| 8413 | * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator |
| 8414 | * apps and protected system packages. |
| 8415 | */ |
| 8416 | void onApplicationUserDataCleared(String packageName, boolean succeeded); |
| 8417 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 8418 | } |