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; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 42 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 43 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 44 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 45 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 46 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 47 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 48 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 49 | import android.os.Bundle; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 50 | import android.os.Parcelable; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 51 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 52 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 53 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 54 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 56 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 57 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 58 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 59 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 60 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 61 | import android.telephony.TelephonyManager; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 62 | import android.util.ArraySet; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 63 | import android.util.Log; |
| 64 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 65 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 66 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 67 | |
| 68 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 69 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 70 | import java.lang.annotation.Retention; |
| 71 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 72 | import java.net.InetSocketAddress; |
| 73 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 74 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 75 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 76 | import java.security.PrivateKey; |
| 77 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 78 | import java.security.cert.CertificateException; |
| 79 | import java.security.cert.CertificateFactory; |
| 80 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 81 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 82 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 83 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 84 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 85 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 86 | import java.util.List; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 87 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 90 | * 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] | 91 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 92 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 93 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 94 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 95 | * application calling an api may only pass as an argument a device administrator component it |
| 96 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 97 | * <div class="special reference"> |
| 98 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 99 | * <p> |
| 100 | * For more information about managing policies for device administration, read the <a href= |
| 101 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 102 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 103 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 104 | @SystemService(Context.DEVICE_POLICY_SERVICE) |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 105 | public class DevicePolicyManager { |
| 106 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 107 | |
| 108 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 109 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 110 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 111 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 112 | /** @hide */ |
| 113 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 114 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 117 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 119 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 120 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 121 | mContext = context; |
| 122 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 123 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 126 | /** @hide test will override it. */ |
| 127 | @VisibleForTesting |
| 128 | protected int myUserId() { |
| 129 | return UserHandle.myUserId(); |
| 130 | } |
| 131 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 132 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 133 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 134 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 135 | * <p>A managed profile allows data separation for example for the usage of a |
| 136 | * device as a personal and corporate device. The user which provisioning is started from and |
| 137 | * the managed profile share a launcher. |
| 138 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 139 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 140 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 141 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 142 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 143 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 144 | * {@link #isProvisioningAllowed(String)}. |
| 145 | * |
| 146 | * <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] | 147 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 148 | * 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] | 149 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 150 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 151 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 152 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 153 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 154 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 155 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 156 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 157 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 158 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 159 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 160 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 161 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 162 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 163 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 164 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 165 | * <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] | 166 | * in the provisioning intent. The |
| 167 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 168 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 169 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 170 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 171 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 172 | * completed, along with the above broadcast, activity intent |
| 173 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in |
| 174 | * the provisioning intent. |
| 175 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 176 | * <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] | 177 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 178 | * |
| 179 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 180 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 181 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 182 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 183 | * 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] | 184 | */ |
| 185 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 186 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 187 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 188 | |
| 189 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 190 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 191 | * |
| 192 | * <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] | 193 | * 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] | 194 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 195 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 196 | * allowed. |
| 197 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 198 | * <p>The intent contains the following extras: |
| 199 | * <ul> |
| 200 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 201 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 202 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 203 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 204 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 205 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 206 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 207 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 208 | * |
| 209 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 210 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 211 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 212 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 213 | * 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] | 214 | * |
| 215 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 216 | */ |
| 217 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 218 | public static final String ACTION_PROVISION_MANAGED_USER |
| 219 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 220 | |
| 221 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 222 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 223 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 224 | * |
| 225 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 226 | * A device owner has full control over the device. The device owner can not be modified by the |
| 227 | * user. |
| 228 | * |
| 229 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 230 | * employee or client. |
| 231 | * |
| 232 | * <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] | 233 | * It is possible to check if provisioning is allowed or not by querying the method |
| 234 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 235 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 236 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 237 | * <ul> |
| 238 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 239 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 240 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 241 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 242 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 243 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 244 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 245 | * </ul> |
| 246 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 247 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 248 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 249 | * device owner. |
| 250 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 251 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 252 | * completed, along with the above broadcast, activity intent |
| 253 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 254 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 255 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 256 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 257 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 258 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 259 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 260 | * 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] | 261 | */ |
| 262 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 263 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 264 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 265 | |
| 266 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 267 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 268 | * |
| 269 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 270 | * the device. A device owner has full control over the device. The device owner can not be |
| 271 | * modified by the user and the only way of resetting the device is via factory reset. |
| 272 | * |
| 273 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 274 | * employee or client. |
| 275 | * |
| 276 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 277 | * |
| 278 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 279 | * by a privileged app with the permission |
| 280 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 281 | * |
| 282 | * <p>The provisioning intent contains the following properties: |
| 283 | * <ul> |
| 284 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 285 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 286 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 287 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 288 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 289 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 290 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 291 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 292 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 293 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 294 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 295 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 296 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 297 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 298 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 299 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 300 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 301 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 302 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 303 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 304 | * |
| 305 | * @hide |
| 306 | */ |
| 307 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 308 | @SystemApi |
| 309 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 310 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 311 | |
| 312 | /** |
| 313 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 314 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 315 | * |
| 316 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 317 | * management state that is distinct from that reached by |
| 318 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 319 | * user, and only has control over device-wide policies, not individual users and their data. |
| 320 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 321 | * this form of device management. |
| 322 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 323 | * <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] | 324 | * A device owner has full control over the device. The device owner can not be modified by the |
| 325 | * user. |
| 326 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 327 | * <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] | 328 | * employee or client. |
| 329 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 330 | * <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] | 331 | * It is possible to check if provisioning is allowed or not by querying the method |
| 332 | * {@link #isProvisioningAllowed(String)}. |
| 333 | * |
| 334 | * <p>The intent contains the following extras: |
| 335 | * <ul> |
| 336 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 337 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 338 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 339 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 340 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 341 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 342 | * </ul> |
| 343 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 344 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 345 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 346 | * device owner. |
| 347 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 348 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 349 | * completed, along with the above broadcast, activity intent |
| 350 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 351 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 352 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 353 | * |
| 354 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 355 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 356 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 357 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 358 | * |
| 359 | * @hide |
| 360 | */ |
| 361 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 362 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 363 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 364 | |
| 365 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 366 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 367 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 368 | * <ul> |
| 369 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 370 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 371 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 372 | * </ul> |
| 373 | * |
| 374 | * @hide |
| 375 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 376 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 377 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 378 | public static final String ACTION_PROVISION_FINALIZATION |
| 379 | = "android.app.action.PROVISION_FINALIZATION"; |
| 380 | |
| 381 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 382 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 383 | * |
| 384 | * @hide |
| 385 | */ |
| 386 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 387 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 388 | |
| 389 | /** |
| 390 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 391 | * |
| 392 | * @hide |
| 393 | */ |
| 394 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 395 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 396 | |
| 397 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 398 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 399 | * |
| 400 | * @hide |
| 401 | */ |
| 402 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 403 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 404 | |
| 405 | /** |
| 406 | * Extra for shared bugreport's SHA-256 hash. |
| 407 | * |
| 408 | * @hide |
| 409 | */ |
| 410 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 411 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 412 | |
| 413 | /** |
| 414 | * Extra for remote bugreport notification shown type. |
| 415 | * |
| 416 | * @hide |
| 417 | */ |
| 418 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 419 | "android.app.extra.bugreport_notification_type"; |
| 420 | |
| 421 | /** |
| 422 | * Notification type for a started remote bugreport flow. |
| 423 | * |
| 424 | * @hide |
| 425 | */ |
| 426 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 427 | |
| 428 | /** |
| 429 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 430 | * being taken. |
| 431 | * |
| 432 | * @hide |
| 433 | */ |
| 434 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 435 | |
| 436 | /** |
| 437 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 438 | * |
| 439 | * @hide |
| 440 | */ |
| 441 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 442 | |
| 443 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 444 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 445 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 446 | * |
| 447 | * @hide |
| 448 | */ |
| 449 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 450 | |
| 451 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 452 | * 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] | 453 | * allows a mobile device management application or NFC programmer application which starts |
| 454 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 455 | * <p> |
| 456 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 457 | * sends the intent to pass data to itself on the newly created profile. |
| 458 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 459 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 460 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 461 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 462 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 463 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 464 | * management application after provisioning. |
| 465 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 466 | * <p> |
| 467 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 468 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 469 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 470 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 471 | */ |
| 472 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 473 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 474 | |
| 475 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 476 | * A String extra holding the package name of the mobile device management application that |
| 477 | * will be set as the profile owner or device owner. |
| 478 | * |
| 479 | * <p>If an application starts provisioning directly via an intent with action |
| 480 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 481 | * application that started provisioning. The package will be set as profile owner in that case. |
| 482 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 483 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 484 | * 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] | 485 | * |
| 486 | * <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] | 487 | * 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] | 488 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 489 | * @see DeviceAdminReceiver |
| 490 | * @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] | 491 | * supported, but only if there is only one device admin receiver in the package that requires |
| 492 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 493 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 494 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 495 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 496 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 497 | |
| 498 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 499 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 500 | * application that will be set as the profile owner or device owner and active admin. |
| 501 | * |
| 502 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 503 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 504 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 505 | * 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] | 506 | * |
| 507 | * <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] | 508 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 509 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 510 | * {@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] | 511 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 512 | * |
| 513 | * @see DeviceAdminReceiver |
| 514 | */ |
| 515 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 516 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 517 | |
| 518 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 519 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 520 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 521 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 522 | * |
| 523 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 524 | */ |
| 525 | |
| 526 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 527 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 528 | |
| 529 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 530 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 531 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 532 | * the account will not be removed from the primary user after it is migrated to the newly |
| 533 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 534 | * |
| 535 | * <p> Defaults to {@code false} |
| 536 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 537 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 538 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 539 | */ |
| 540 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 541 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 542 | |
| 543 | /** |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 544 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the |
| 545 | * device. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 546 | */ |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 547 | @Deprecated |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 548 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 549 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 550 | |
| 551 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 552 | * A integer extra indicating the predominant color to show during the provisioning. |
| 553 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 554 | * |
| 555 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 556 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 557 | */ |
| 558 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 559 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 560 | |
| 561 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 562 | * 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] | 563 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 564 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 565 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 566 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 567 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 568 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 569 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 570 | |
| 571 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 572 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 573 | * will be set to. |
| 574 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 575 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 576 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 577 | */ |
| 578 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 579 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 580 | |
| 581 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 582 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 583 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 584 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 585 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 586 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 587 | */ |
| 588 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 589 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 590 | |
| 591 | /** |
| 592 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 593 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 594 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 595 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 596 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 597 | */ |
| 598 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 599 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 600 | |
| 601 | /** |
| 602 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 603 | * owner provisioning for downloading the mobile device management application. |
| 604 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 605 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 606 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 607 | */ |
| 608 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 609 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 610 | |
| 611 | /** |
| 612 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 613 | * is hidden or not. |
| 614 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 615 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 616 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 617 | */ |
| 618 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 619 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 620 | |
| 621 | /** |
| 622 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 623 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 624 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 625 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 626 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 627 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 628 | */ |
| 629 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 630 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 631 | |
| 632 | /** |
| 633 | * A String extra holding the password of the wifi network in |
| 634 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 635 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 636 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 637 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 638 | */ |
| 639 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 640 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 641 | |
| 642 | /** |
| 643 | * A String extra holding the proxy host for the wifi network in |
| 644 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 645 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 646 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 647 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 648 | */ |
| 649 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 650 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 651 | |
| 652 | /** |
| 653 | * An int extra holding the proxy port for the wifi network in |
| 654 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 655 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 656 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 657 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 658 | */ |
| 659 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 660 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 661 | |
| 662 | /** |
| 663 | * A String extra holding the proxy bypass for the wifi network in |
| 664 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 665 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 666 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 667 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 668 | */ |
| 669 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 670 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 671 | |
| 672 | /** |
| 673 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 674 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 675 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 676 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 677 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 678 | */ |
| 679 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 680 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 681 | |
| 682 | /** |
| 683 | * A String extra holding a url that specifies the download location of the device admin |
| 684 | * package. When not provided it is assumed that the device admin package is already installed. |
| 685 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 686 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 687 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 688 | */ |
| 689 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 690 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 691 | |
| 692 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 693 | * A String extra holding the localized name of the organization under management. |
| 694 | * |
| 695 | * The name is displayed only during provisioning. |
| 696 | * |
| 697 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 698 | * |
| 699 | * @hide |
| 700 | */ |
| 701 | @SystemApi |
| 702 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 703 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 704 | |
| 705 | /** |
Alejandro Fernández | bfd6193 | 2017-04-04 19:33:01 +0100 | [diff] [blame] | 706 | * A String extra holding a url to the website of the device provider so the user can open it |
| 707 | * 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] | 708 | * |
| 709 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 710 | * |
| 711 | * @hide |
| 712 | */ |
| 713 | @SystemApi |
| 714 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 715 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 716 | |
| 717 | /** |
| 718 | * A String extra holding the localized name of the device admin package. It should be the same |
| 719 | * as the app label of the package. |
| 720 | * |
| 721 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 722 | * |
| 723 | * @hide |
| 724 | */ |
| 725 | @SystemApi |
| 726 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 727 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 728 | |
| 729 | /** |
| 730 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 731 | * shown during the provisioning. |
| 732 | * <h5>The following URI schemes are accepted:</h5> |
| 733 | * <ul> |
| 734 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 735 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 736 | * </ul> |
| 737 | * |
| 738 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 739 | * pixel density for the device. |
| 740 | * |
| 741 | * <p> If a content: URI is passed, the intent should have the flag |
| 742 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 743 | * {@link android.content.ClipData} of the intent too. |
| 744 | * |
| 745 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 746 | * |
| 747 | * @hide |
| 748 | */ |
| 749 | @SystemApi |
| 750 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 751 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 752 | |
| 753 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 754 | * An int extra holding a minimum required version code for the device admin package. If the |
| 755 | * device admin is already installed on the device, it will only be re-downloaded from |
| 756 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 757 | * installed package is less than this version code. |
| 758 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 759 | * <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] | 760 | * provisioning via an NFC bump. |
| 761 | */ |
| 762 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 763 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 764 | |
| 765 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 766 | * A String extra holding a http cookie header which should be used in the http request to the |
| 767 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 768 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 769 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 770 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 771 | */ |
| 772 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 773 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 774 | |
| 775 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 776 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 777 | * the file at download location specified in |
| 778 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 779 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 780 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 781 | * 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] | 782 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 783 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 784 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 785 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 786 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 787 | * |
| 788 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 789 | * 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] | 790 | * 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] | 791 | * 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] | 792 | */ |
| 793 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 794 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 795 | |
| 796 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 797 | * 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] | 798 | * android package archive at the download location specified in {@link |
| 799 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 800 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 801 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 802 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 803 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 804 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 805 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 806 | * 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] | 807 | * the download location. If the checksum does not match an error will be shown to the user and |
| 808 | * the user will be asked to factory reset the device. |
| 809 | * |
| 810 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 811 | * provisioning via an NFC bump. |
| 812 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 813 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 814 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 815 | |
| 816 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 817 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 818 | * has completed successfully. |
| 819 | * |
| 820 | * <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] | 821 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 822 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 823 | * <p>This intent will contain the following extras |
| 824 | * <ul> |
| 825 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 826 | * profile.</li> |
| 827 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 828 | * be migrated at provisioning time, if any.</li> |
| 829 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 830 | */ |
| 831 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 832 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 833 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 834 | |
| 835 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 836 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 837 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 838 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 839 | * delivered faster as it's an activity intent. |
| 840 | * |
| 841 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 842 | * the device owner case the profile is the primary user. |
| 843 | * |
| 844 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 845 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 846 | */ |
| 847 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 848 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 849 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 850 | |
| 851 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 852 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 853 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 854 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 855 | * <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] | 856 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 857 | * |
| 858 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 859 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 860 | */ |
| 861 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 862 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 863 | |
| 864 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 865 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 866 | * provisioning. If this extra is not passed, a default image will be shown. |
| 867 | * <h5>The following URI schemes are accepted:</h5> |
| 868 | * <ul> |
| 869 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 870 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 871 | * </ul> |
| 872 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 873 | * <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] | 874 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 875 | * |
| 876 | * <p> If a content: URI is passed, the intent should have the flag |
| 877 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 878 | * {@link android.content.ClipData} of the intent too. |
| 879 | * |
| 880 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 881 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 882 | */ |
| 883 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 884 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 885 | |
| 886 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 887 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 888 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 889 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 890 | * content. |
| 891 | * |
| 892 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 893 | * management application (MDM), and one disclaimer from the organization. |
| 894 | * |
| 895 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 896 | * |
| 897 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 898 | * |
| 899 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 900 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 901 | */ |
| 902 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 903 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 904 | |
| 905 | /** |
| 906 | * A String extra of localized disclaimer header. |
| 907 | * |
| 908 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 909 | * or the organization name. |
| 910 | * |
| 911 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 912 | * |
| 913 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 914 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 915 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 916 | * |
| 917 | * <pre> |
| 918 | * <meta-data |
| 919 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 920 | * android:resource="@string/disclaimer_header" |
| 921 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 922 | */ |
| 923 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 924 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 925 | |
| 926 | /** |
| 927 | * A {@link Uri} extra pointing to disclaimer content. |
| 928 | * |
| 929 | * <h5>The following URI schemes are accepted:</h5> |
| 930 | * <ul> |
| 931 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 932 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 933 | * </ul> |
| 934 | * |
| 935 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 936 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 937 | * {@link android.widget.TextView}. |
| 938 | * |
| 939 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 940 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 941 | * {@link android.content.ClipData} of the intent too. |
| 942 | * |
| 943 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 944 | * |
| 945 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 946 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 947 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 948 | * |
| 949 | * <pre> |
| 950 | * <meta-data |
| 951 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 952 | * android:resource="@string/disclaimer_content" |
| 953 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 954 | */ |
| 955 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 956 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 957 | |
| 958 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 959 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 960 | * during setup-wizard. |
| 961 | * |
| 962 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 963 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 964 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 965 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 966 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 967 | * |
| 968 | * @hide |
| 969 | */ |
| 970 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 971 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 972 | |
| 973 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 974 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 975 | * skipped. If unspecified, defaults to {@code false}. |
| 976 | * |
| 977 | * It can only be used by an existing device owner trying to create a managed profile via |
| 978 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 979 | */ |
| 980 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 981 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 982 | |
| 983 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 984 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 985 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 986 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 987 | * A device owner has full control over the device. The device owner can not be modified by the |
| 988 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 989 | * reset. |
| 990 | * |
| 991 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 992 | * employee or client. |
| 993 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 994 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 995 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 996 | * <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] | 997 | * contains the following properties: |
| 998 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 999 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 1000 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 1001 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1002 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1003 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1004 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1005 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1006 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1007 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1008 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1009 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1010 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1011 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1012 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1013 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1014 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1015 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1016 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1017 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1018 | * 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] | 1019 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1020 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1021 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1022 | */ |
| 1023 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1024 | = "application/com.android.managedprovisioning"; |
| 1025 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1026 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1027 | * Activity action: ask the user to add a new device administrator to the system. |
| 1028 | * The desired policy is the ComponentName of the policy in the |
| 1029 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1030 | * bring the user through adding the device administrator to the system (or |
| 1031 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1032 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1033 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1034 | * field to provide the user with additional explanation (in addition |
| 1035 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1036 | * |
| 1037 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1038 | * user intervention). However, if your administrator has been updated and is requesting |
| 1039 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1040 | * 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] | 1041 | */ |
| 1042 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1043 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1044 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1045 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1046 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1047 | * @hide |
| 1048 | * 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] | 1049 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1050 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1051 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1052 | * 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] | 1053 | * to remotely control restrictions on the user. |
| 1054 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1055 | * <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] | 1056 | * result of whether or not the user approved the action. If approved, the result will |
| 1057 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1058 | * as a profile owner. |
| 1059 | * |
| 1060 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1061 | * field to provide the user with additional explanation (in addition |
| 1062 | * to your component's description) about what is being added. |
| 1063 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1064 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1065 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1066 | */ |
| 1067 | @SystemApi |
| 1068 | public static final String ACTION_SET_PROFILE_OWNER |
| 1069 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1070 | |
| 1071 | /** |
| 1072 | * @hide |
| 1073 | * Name of the profile owner admin that controls the user. |
| 1074 | */ |
| 1075 | @SystemApi |
| 1076 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1077 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1078 | |
| 1079 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1080 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1081 | * 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] | 1082 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1083 | * @hide |
| 1084 | */ |
| 1085 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1086 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1087 | |
| 1088 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1089 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1090 | * |
| 1091 | * This broadcast is sent only to the primary user. |
| 1092 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1093 | */ |
| 1094 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1095 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1096 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1097 | |
| 1098 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1099 | * The ComponentName of the administrator component. |
| 1100 | * |
| 1101 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1102 | */ |
| 1103 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1104 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1105 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1106 | * An optional CharSequence providing additional explanation for why the |
| 1107 | * admin is being added. |
| 1108 | * |
| 1109 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1110 | */ |
| 1111 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1112 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1113 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1114 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1115 | * {@link #createAdminSupportIntent(String)}. |
| 1116 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1117 | */ |
| 1118 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1119 | |
| 1120 | /** |
| 1121 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1122 | * {@link #createAdminSupportIntent(String)}. |
| 1123 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1124 | */ |
| 1125 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1126 | |
| 1127 | /** |
| 1128 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1129 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
| 1130 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 1131 | * @see #createAdminSupportIntent(String) |
| 1132 | * @hide |
| 1133 | */ |
| 1134 | @TestApi |
| 1135 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1136 | |
| 1137 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1138 | * Activity action: have the user enter a new password. This activity should |
| 1139 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1140 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1141 | * enter a new password that meets the current requirements. You can use |
| 1142 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1143 | * have the user select a new password in order to meet the current |
| 1144 | * constraints. Upon being resumed from this activity, you can check the new |
| 1145 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1146 | * |
| 1147 | * If the intent is launched from within a managed profile with a profile |
| 1148 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1149 | * this will trigger entering a new password for the parent of the profile. |
| 1150 | * For all other cases it will trigger entering a new password for the user |
| 1151 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1152 | * |
| 1153 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1154 | */ |
| 1155 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1156 | public static final String ACTION_SET_NEW_PASSWORD |
| 1157 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1158 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1159 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1160 | * Activity action: have the user enter a new password for the parent profile. |
| 1161 | * If the intent is launched from within a managed profile, this will trigger |
| 1162 | * entering a new password for the parent of the profile. In all other cases |
| 1163 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1164 | */ |
| 1165 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1166 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1167 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1168 | |
| 1169 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1170 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1171 | * Network logging was enabled and the user tapped the notification. |
| 1172 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1173 | * @hide |
| 1174 | */ |
| 1175 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1176 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1177 | |
| 1178 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1179 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1180 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1181 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1182 | * |
| 1183 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1184 | */ |
| 1185 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1186 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1187 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1188 | |
| 1189 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1190 | * 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] | 1191 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1192 | */ |
| 1193 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1194 | |
| 1195 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1196 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1197 | * the parent profile to access intents sent from the managed profile. |
| 1198 | * That is, when an app in the managed profile calls |
| 1199 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1200 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1201 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1202 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1203 | |
| 1204 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1205 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1206 | * the managed profile to access intents sent from the parent profile. |
| 1207 | * That is, when an app in the parent profile calls |
| 1208 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1209 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1210 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1211 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1212 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1213 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1214 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1215 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1216 | */ |
| 1217 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1218 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1219 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1220 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1221 | /** |
| 1222 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1223 | * Already granted or denied permissions are not affected by this. |
| 1224 | */ |
| 1225 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1226 | |
| 1227 | /** |
| 1228 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1229 | * Already granted or denied permissions are not affected by this. |
| 1230 | */ |
| 1231 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1232 | |
| 1233 | /** |
| 1234 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1235 | * Already granted or denied permissions are not affected by this. |
| 1236 | */ |
| 1237 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1238 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1239 | /** |
| 1240 | * Runtime permission state: The user can manage the permission |
| 1241 | * through the UI. |
| 1242 | */ |
| 1243 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1244 | |
| 1245 | /** |
| 1246 | * Runtime permission state: The permission is granted to the app |
| 1247 | * and the user cannot manage the permission through the UI. |
| 1248 | */ |
| 1249 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1250 | |
| 1251 | /** |
| 1252 | * Runtime permission state: The permission is denied to the app |
| 1253 | * and the user cannot manage the permission through the UI. |
| 1254 | */ |
| 1255 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1256 | |
| 1257 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1258 | * Delegation of certificate installation and management. This scope grants access to the |
| 1259 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1260 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1261 | */ |
| 1262 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1263 | |
| 1264 | /** |
| 1265 | * Delegation of application restrictions management. This scope grants access to the |
| 1266 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1267 | */ |
| 1268 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1269 | |
| 1270 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1271 | * Delegation of application uninstall block. This scope grants access to the |
| 1272 | * {@link #setUninstallBlocked} API. |
| 1273 | */ |
| 1274 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1275 | |
| 1276 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1277 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1278 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1279 | * and {@link #setPermissionGrantState} APIs. |
| 1280 | */ |
| 1281 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1282 | |
| 1283 | /** |
| 1284 | * Delegation of package access state. This scope grants access to the |
| 1285 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1286 | * {@link #setPackagesSuspended} APIs. |
| 1287 | */ |
| 1288 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1289 | |
| 1290 | /** |
| 1291 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1292 | * API. |
| 1293 | */ |
| 1294 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1295 | |
| 1296 | /** |
| 1297 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1298 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1299 | * @hide |
| 1300 | */ |
| 1301 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1302 | "delegation-keep-uninstalled-packages"; |
| 1303 | |
| 1304 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1305 | * No management for current user in-effect. This is the default. |
| 1306 | * @hide |
| 1307 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1308 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1309 | public static final int STATE_USER_UNMANAGED = 0; |
| 1310 | |
| 1311 | /** |
| 1312 | * Management partially setup, user setup needs to be completed. |
| 1313 | * @hide |
| 1314 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1315 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1316 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1317 | |
| 1318 | /** |
| 1319 | * Management partially setup, user setup completed. |
| 1320 | * @hide |
| 1321 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1322 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1323 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1324 | |
| 1325 | /** |
| 1326 | * Management setup and active on current user. |
| 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_SETUP_FINALIZED = 3; |
| 1331 | |
| 1332 | /** |
| 1333 | * Management partially setup on a managed profile. |
| 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_PROFILE_COMPLETE = 4; |
| 1338 | |
| 1339 | /** |
| 1340 | * @hide |
| 1341 | */ |
| 1342 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1343 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1344 | @Retention(RetentionPolicy.SOURCE) |
| 1345 | public @interface UserProvisioningState {} |
| 1346 | |
| 1347 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1348 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1349 | * |
| 1350 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1351 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1352 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1353 | * |
| 1354 | * @hide |
| 1355 | */ |
| 1356 | public static final int CODE_OK = 0; |
| 1357 | |
| 1358 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1359 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1360 | * |
| 1361 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1362 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1363 | * owner. |
| 1364 | * |
| 1365 | * @hide |
| 1366 | */ |
| 1367 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1368 | |
| 1369 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1370 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1371 | * |
| 1372 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1373 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1374 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1375 | * |
| 1376 | * @hide |
| 1377 | */ |
| 1378 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1379 | |
| 1380 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1381 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1382 | * |
| 1383 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1384 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1385 | * |
| 1386 | * @hide |
| 1387 | */ |
| 1388 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 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} if the device has already been setup and |
| 1395 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1396 | * |
| 1397 | * @hide |
| 1398 | */ |
| 1399 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1400 | |
| 1401 | /** |
| 1402 | * Code used to indicate that the device also has a user other than the system user. |
| 1403 | * |
| 1404 | * @hide |
| 1405 | */ |
| 1406 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1407 | |
| 1408 | /** |
| 1409 | * Code used to indicate that device has an account that prevents provisioning. |
| 1410 | * |
| 1411 | * @hide |
| 1412 | */ |
| 1413 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1414 | |
| 1415 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1416 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1417 | * |
| 1418 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1419 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1420 | * |
| 1421 | * @hide |
| 1422 | */ |
| 1423 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1424 | |
| 1425 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1426 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1427 | * |
| 1428 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1429 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1430 | * when the device is a watch and is already paired. |
| 1431 | * |
| 1432 | * @hide |
| 1433 | */ |
| 1434 | public static final int CODE_HAS_PAIRED = 8; |
| 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_PROFILE} and |
| 1440 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1441 | * |
| 1442 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1443 | * @hide |
| 1444 | */ |
| 1445 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1446 | |
| 1447 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1448 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1449 | * |
| 1450 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1451 | * |
| 1452 | * @hide |
| 1453 | */ |
| 1454 | public static final int CODE_SYSTEM_USER = 10; |
| 1455 | |
| 1456 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1457 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1458 | * |
| 1459 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1460 | * managed profiles. |
| 1461 | * |
| 1462 | * @hide |
| 1463 | */ |
| 1464 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1465 | |
| 1466 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1467 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1468 | * |
| 1469 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1470 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1471 | * user. |
| 1472 | * |
| 1473 | * @hide |
| 1474 | */ |
| 1475 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 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_DEVICE}, |
| 1481 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1482 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1483 | * admins. |
| 1484 | * |
| 1485 | * @hide |
| 1486 | */ |
| 1487 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1488 | |
| 1489 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1490 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1491 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1492 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1493 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1494 | * |
| 1495 | * @hide |
| 1496 | */ |
| 1497 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1498 | |
| 1499 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1500 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1501 | * |
| 1502 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1503 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1504 | * |
| 1505 | * @hide |
| 1506 | */ |
| 1507 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1508 | |
| 1509 | /** |
| 1510 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1511 | * conditions. |
| 1512 | * |
| 1513 | * @hide |
| 1514 | */ |
| 1515 | @Retention(RetentionPolicy.SOURCE) |
| 1516 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1517 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1518 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1519 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1520 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1521 | public @interface ProvisioningPreCondition {} |
| 1522 | |
| 1523 | /** |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1524 | * Service action: Action for a service that device owner and profile owner can optionally |
| 1525 | * own. If a device owner or a profile owner has such a service, the system tries to keep |
| 1526 | * 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] | 1527 | * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN} |
| 1528 | * permission. |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1529 | */ |
| 1530 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
| 1531 | public static final String ACTION_DEVICE_ADMIN_SERVICE |
| 1532 | = "android.app.action.DEVICE_ADMIN_SERVICE"; |
| 1533 | |
| 1534 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1535 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1536 | * |
| 1537 | * @param admin The administrator component to check for. |
| 1538 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1539 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1540 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1541 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1542 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1543 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | /** |
| 1547 | * @see #isAdminActive(ComponentName) |
| 1548 | * @hide |
| 1549 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1550 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1551 | if (mService != null) { |
| 1552 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1553 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1554 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1555 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | return false; |
| 1559 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1560 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1561 | /** |
| 1562 | * Return true if the given administrator component is currently being removed |
| 1563 | * for the user. |
| 1564 | * @hide |
| 1565 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1566 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1567 | if (mService != null) { |
| 1568 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1569 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1570 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1571 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1572 | } |
| 1573 | } |
| 1574 | return false; |
| 1575 | } |
| 1576 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1577 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1578 | * Return a list of all currently active device administrators' component |
| 1579 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1580 | * returned. |
| 1581 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1582 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1583 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1584 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | /** |
| 1588 | * @see #getActiveAdmins() |
| 1589 | * @hide |
| 1590 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1591 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1592 | if (mService != null) { |
| 1593 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1594 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1595 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1596 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1597 | } |
| 1598 | } |
| 1599 | return null; |
| 1600 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1601 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1602 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1603 | * Used by package administration code to determine if a package can be stopped |
| 1604 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1605 | * @hide |
| 1606 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1607 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 1608 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1609 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1610 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * Used by package administration code to determine if a package can be stopped |
| 1615 | * or uninstalled. |
| 1616 | * @hide |
| 1617 | */ |
| 1618 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1619 | if (mService != null) { |
| 1620 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1621 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1622 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1623 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | return false; |
| 1627 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1628 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1629 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1630 | * Remove a current administration component. This can only be called |
| 1631 | * by the application that owns the administration component; if you |
| 1632 | * try to remove someone else's component, a security exception will be |
| 1633 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1634 | * |
| 1635 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1636 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1637 | * |
| 1638 | * @param admin The administration compononent to remove. |
| 1639 | * @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] | 1640 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1641 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1642 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1643 | if (mService != null) { |
| 1644 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1645 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1646 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1647 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1651 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1652 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1653 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1654 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1655 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1656 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1657 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1658 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1659 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1660 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1661 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1662 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1663 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1664 | if (mService != null) { |
| 1665 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1666 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1667 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1668 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | return false; |
| 1672 | } |
| 1673 | |
| 1674 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1675 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1676 | * |
| 1677 | * @hide |
| 1678 | */ |
| 1679 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1680 | if (mService != null) { |
| 1681 | try { |
| 1682 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1683 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1684 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | return false; |
| 1688 | } |
| 1689 | |
| 1690 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1691 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1692 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1693 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1694 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1695 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1696 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1697 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1698 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1699 | * recognition technology. This implies technologies that can recognize the identity of |
| 1700 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1701 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1702 | */ |
| 1703 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1704 | |
| 1705 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1706 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1707 | * 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] | 1708 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1709 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1710 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1711 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1712 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1713 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1714 | * password containing at least numeric characters. Note that quality |
| 1715 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1716 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1717 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1718 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1719 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1720 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1721 | * password containing at least numeric characters with no repeating (4444) |
| 1722 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1723 | * constants are ordered so that higher values are more restrictive. |
| 1724 | */ |
| 1725 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1726 | |
| 1727 | /** |
| 1728 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1729 | * password containing at least alphabetic (or other symbol) characters. |
| 1730 | * Note that quality constants are ordered so that higher values are more |
| 1731 | * restrictive. |
| 1732 | */ |
| 1733 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1734 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1735 | /** |
| 1736 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1737 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1738 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1739 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1740 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1741 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1742 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1743 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1744 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1745 | * password containing at least a letter, a numerical digit and a special |
| 1746 | * symbol, by default. With this password quality, passwords can be |
| 1747 | * restricted to contain various sets of characters, like at least an |
| 1748 | * uppercase letter, etc. These are specified using various methods, |
| 1749 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1750 | * that quality constants are ordered so that higher values are more |
| 1751 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1752 | */ |
| 1753 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1754 | |
| 1755 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1756 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1757 | * modify password. In case this password quality is set, the password is |
| 1758 | * managed by a profile owner. The profile owner can set any password, |
| 1759 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1760 | * that quality constants are ordered so that higher values are more |
| 1761 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1762 | * the highest. |
| 1763 | * @hide |
| 1764 | */ |
| 1765 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1766 | |
| 1767 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1768 | * @hide |
| 1769 | * |
| 1770 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1771 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1772 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1773 | * used by authenticator to exempt their accounts from this: |
| 1774 | * |
| 1775 | * <ul> |
| 1776 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1777 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1778 | * <application> tag in the manifest. |
| 1779 | * |
| 1780 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1781 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1782 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1783 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1784 | * if any of the accounts have it. |
| 1785 | * </ul> |
| 1786 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1787 | @SystemApi |
| 1788 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1789 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1790 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1791 | |
| 1792 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1793 | @SystemApi |
| 1794 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1795 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1796 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1797 | |
| 1798 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1799 | * Called by an application that is administering the device to set the password restrictions it |
| 1800 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1801 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1802 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1803 | * 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] | 1804 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1805 | * <p> |
| 1806 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1807 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1808 | * considerations) is the one that is in effect. |
| 1809 | * <p> |
| 1810 | * The calling device admin must have requested |
| 1811 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1812 | * not, a security exception will be thrown. |
| 1813 | * <p> |
| 1814 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1815 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1816 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1817 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1818 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1819 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1820 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1821 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1822 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1823 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1824 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1825 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1826 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1827 | if (mService != null) { |
| 1828 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1829 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1830 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1831 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1835 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1836 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1837 | * 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] | 1838 | * 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] | 1839 | * a separate challenge are not taken into account. |
| 1840 | * |
| 1841 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1842 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1843 | * restrictions on the parent profile. |
| 1844 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1845 | * @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] | 1846 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1847 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1848 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1849 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1853 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1854 | if (mService != null) { |
| 1855 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1856 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1857 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1858 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1859 | } |
| 1860 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1861 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1862 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1863 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1864 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1865 | * Called by an application that is administering the device to set the minimum allowed password |
| 1866 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1867 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1868 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1869 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1870 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1871 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1872 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1873 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1874 | * {@link #setPasswordQuality}. |
| 1875 | * <p> |
| 1876 | * The calling device admin must have requested |
| 1877 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1878 | * not, a security exception will be thrown. |
| 1879 | * <p> |
| 1880 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1881 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1882 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1883 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1884 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1885 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1886 | * restriction. |
| 1887 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1888 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1889 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1890 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1891 | if (mService != null) { |
| 1892 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1893 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1894 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1895 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1899 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1900 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1901 | * 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] | 1902 | * 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] | 1903 | * a separate challenge are not taken into account. |
| 1904 | * |
| 1905 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1906 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1907 | * restrictions on the parent profile. |
| 1908 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1909 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1910 | * @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] | 1911 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1912 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1913 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1914 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1918 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1919 | if (mService != null) { |
| 1920 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1921 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1922 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1923 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | return 0; |
| 1927 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1928 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1929 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1930 | * Called by an application that is administering the device to set the minimum number of upper |
| 1931 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1932 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1933 | * current password will remain until the user has set a new one, so the change does not take |
| 1934 | * place immediately. To prompt the user for a new password, use |
| 1935 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1936 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1937 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1938 | * <p> |
| 1939 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1940 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1941 | * not, a security exception will be thrown. |
| 1942 | * <p> |
| 1943 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1944 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1945 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1946 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1947 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1948 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1949 | * A value of 0 means there is no restriction. |
| 1950 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1951 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1952 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1953 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1954 | if (mService != null) { |
| 1955 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1956 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1957 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1958 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1959 | } |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1964 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1965 | * 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] | 1966 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1967 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1968 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1969 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1970 | * and only applies when the password quality is |
| 1971 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1972 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1973 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1974 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1975 | * restrictions on the parent profile. |
| 1976 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1977 | * @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] | 1978 | * aggregate all admins. |
| 1979 | * @return The minimum number of upper case letters required in the |
| 1980 | * password. |
| 1981 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1982 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1983 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1987 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1988 | if (mService != null) { |
| 1989 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1990 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1991 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1992 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1999 | * Called by an application that is administering the device to set the minimum number of lower |
| 2000 | * case letters required in the password. After setting this, the user will not be able to enter |
| 2001 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 2002 | * current password will remain until the user has set a new one, so the change does not take |
| 2003 | * place immediately. To prompt the user for a new password, use |
| 2004 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2005 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2006 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2007 | * <p> |
| 2008 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2009 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2010 | * not, a security exception will be thrown. |
| 2011 | * <p> |
| 2012 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2013 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2014 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2015 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2016 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2017 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2018 | * A value of 0 means there is no restriction. |
| 2019 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2020 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2021 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2022 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2023 | if (mService != null) { |
| 2024 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2025 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2026 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2027 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2033 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2034 | * 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] | 2035 | * and its participating profiles. Restrictions on profiles that have |
| 2036 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2037 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2038 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2039 | * and only applies when the password quality is |
| 2040 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2041 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2042 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2043 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2044 | * restrictions on the parent profile. |
| 2045 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2046 | * @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] | 2047 | * aggregate all admins. |
| 2048 | * @return The minimum number of lower case letters required in the |
| 2049 | * password. |
| 2050 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2051 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2052 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2056 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2057 | if (mService != null) { |
| 2058 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2059 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2060 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2061 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
| 2067 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2068 | * Called by an application that is administering the device to set the minimum number of |
| 2069 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2070 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2071 | * password will remain until the user has set a new one, so the change does not take place |
| 2072 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2073 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2074 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2075 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2076 | * <p> |
| 2077 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2078 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2079 | * not, a security exception will be thrown. |
| 2080 | * <p> |
| 2081 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2082 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2083 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2084 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2085 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2086 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2087 | * 0 means there is no restriction. |
| 2088 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2089 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2090 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2091 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2092 | if (mService != null) { |
| 2093 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2094 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2095 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2096 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2102 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2103 | * 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] | 2104 | * and its participating profiles. Restrictions on profiles that have |
| 2105 | * a separate challenge are not taken into account. |
| 2106 | * This is the same value as set by |
| 2107 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2108 | * and only applies when the password quality is |
| 2109 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2110 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2111 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2112 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2113 | * restrictions on the parent profile. |
| 2114 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2115 | * @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] | 2116 | * aggregate all admins. |
| 2117 | * @return The minimum number of letters required in the password. |
| 2118 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2119 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2120 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2124 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2125 | if (mService != null) { |
| 2126 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2127 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2128 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2129 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | return 0; |
| 2133 | } |
| 2134 | |
| 2135 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2136 | * Called by an application that is administering the device to set the minimum number of |
| 2137 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2138 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2139 | * current password will remain until the user has set a new one, so the change does not take |
| 2140 | * place immediately. To prompt the user for a new password, use |
| 2141 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2142 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2143 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2144 | * <p> |
| 2145 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2146 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2147 | * not, a security exception will be thrown. |
| 2148 | * <p> |
| 2149 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2150 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2151 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2152 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2153 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2154 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2155 | * value of 0 means there is no restriction. |
| 2156 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2157 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2158 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2159 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2160 | if (mService != null) { |
| 2161 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2162 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2163 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2164 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2165 | } |
| 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | /** |
| 2170 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2171 | * 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] | 2172 | * and its participating profiles. Restrictions on profiles that have |
| 2173 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2174 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2175 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2176 | * and only applies when the password quality is |
| 2177 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2178 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2179 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2180 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2181 | * restrictions on the parent profile. |
| 2182 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2183 | * @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] | 2184 | * aggregate all admins. |
| 2185 | * @return The minimum number of numerical digits required in the password. |
| 2186 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2187 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2188 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2192 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2193 | if (mService != null) { |
| 2194 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2195 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2196 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2197 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
| 2203 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2204 | * Called by an application that is administering the device to set the minimum number of |
| 2205 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2206 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2207 | * password will remain until the user has set a new one, so the change does not take place |
| 2208 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2209 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2210 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2211 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2212 | * <p> |
| 2213 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2214 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2215 | * not, a security exception will be thrown. |
| 2216 | * <p> |
| 2217 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2218 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2219 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2220 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2221 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2222 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2223 | * 0 means there is no restriction. |
| 2224 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2225 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2226 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2227 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2228 | if (mService != null) { |
| 2229 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2230 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2231 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2232 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2238 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2239 | * 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] | 2240 | * and its participating profiles. Restrictions on profiles that have |
| 2241 | * a separate challenge are not taken into account. This is the same value as |
| 2242 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2243 | * and only applies when the password quality is |
| 2244 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2245 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2246 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2247 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2248 | * restrictions on the parent profile. |
| 2249 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2250 | * @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] | 2251 | * aggregate all admins. |
| 2252 | * @return The minimum number of symbols required in the password. |
| 2253 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2254 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2255 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2259 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2260 | if (mService != null) { |
| 2261 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2262 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2263 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2264 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | return 0; |
| 2268 | } |
| 2269 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2270 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2271 | * Called by an application that is administering the device to set the minimum number of |
| 2272 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2273 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2274 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2275 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2276 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2277 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2278 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2279 | * <p> |
| 2280 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2281 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2282 | * not, a security exception will be thrown. |
| 2283 | * <p> |
| 2284 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2285 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2286 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2287 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2288 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2289 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2290 | * 0 means there is no restriction. |
| 2291 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2292 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2293 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2294 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2295 | if (mService != null) { |
| 2296 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2297 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2298 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2299 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2305 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2306 | * 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] | 2307 | * and its participating profiles. Restrictions on profiles that have |
| 2308 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2309 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2310 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2311 | * and only applies when the password quality is |
| 2312 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2313 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2314 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2315 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2316 | * restrictions on the parent profile. |
| 2317 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2318 | * @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] | 2319 | * aggregate all admins. |
| 2320 | * @return The minimum number of letters required in the password. |
| 2321 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2322 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2323 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2327 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2328 | if (mService != null) { |
| 2329 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2330 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2331 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2332 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | return 0; |
| 2336 | } |
| 2337 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2338 | /** |
| 2339 | * Called by an application that is administering the device to set the length of the password |
| 2340 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2341 | * same as any password in the history. Note that the current password will remain until the |
| 2342 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2343 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2344 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2345 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2346 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2347 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2348 | * <p> |
| 2349 | * The calling device admin must have requested |
| 2350 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2351 | * not, a security exception will be thrown. |
| 2352 | * <p> |
| 2353 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2354 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2355 | * profile. |
| 2356 | * |
| 2357 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2358 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2359 | * restriction. |
| 2360 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2361 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2362 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2363 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2364 | if (mService != null) { |
| 2365 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2366 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2367 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2368 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2369 | } |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2374 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2375 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2376 | * device password (for all admins). |
| 2377 | * <p> |
| 2378 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2379 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2380 | * 432000000 ms for timeout. |
| 2381 | * <p> |
| 2382 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2383 | * <p> |
| 2384 | * The calling device admin must have requested |
| 2385 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2386 | * not, a security exception will be thrown. |
| 2387 | * <p> |
| 2388 | * Note that setting the password will automatically reset the expiration time for all active |
| 2389 | * admins. Active admins do not need to explicitly call this method in that case. |
| 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. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2394 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2395 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2396 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2397 | * there is no restriction (unlimited). |
| 2398 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2399 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2400 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2401 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2402 | if (mService != null) { |
| 2403 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2404 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2405 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2406 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2412 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2413 | * recurring expiration timeout provided in the call to |
| 2414 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2415 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2416 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2417 | * |
| 2418 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2419 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2420 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2421 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2422 | * @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] | 2423 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2424 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2425 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2426 | if (mService != null) { |
| 2427 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2428 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2429 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2430 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
| 2436 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2437 | * 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] | 2438 | * 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] | 2439 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2440 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2441 | * |
| 2442 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2443 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2444 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2445 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2446 | * @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] | 2447 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2448 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2449 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2450 | if (mService != null) { |
| 2451 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2452 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2453 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2454 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | return 0; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2461 | * 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] | 2462 | * 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] | 2463 | * have a separate challenge are not taken into account. |
| 2464 | * |
| 2465 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2466 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2467 | * restrictions on the parent profile. |
| 2468 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2469 | * @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] | 2470 | * all admins. |
| 2471 | * @return The length of the password history |
| 2472 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2473 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2474 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2478 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2479 | if (mService != null) { |
| 2480 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2481 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2482 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2483 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2484 | } |
| 2485 | } |
| 2486 | return 0; |
| 2487 | } |
| 2488 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2489 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2490 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2491 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2492 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2493 | * @return Returns the maximum length that the user can enter. |
| 2494 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2495 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2496 | // Kind-of arbitrary. |
| 2497 | return 16; |
| 2498 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2499 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2500 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2501 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2502 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2503 | * 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] | 2504 | * 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] | 2505 | * <p> |
| 2506 | * The calling device admin must have requested |
| 2507 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2508 | * not, a security exception will be thrown. |
| 2509 | * <p> |
| 2510 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2511 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2512 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2513 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2514 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2515 | * @throws SecurityException if the calling application does not own an active administrator |
| 2516 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2517 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2518 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2519 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2520 | if (mService != null) { |
| 2521 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2522 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2523 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2524 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2525 | } |
| 2526 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2527 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2528 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2529 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2530 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2531 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2532 | * 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] | 2533 | * requested by the admins of the parent user and its profiles. |
| 2534 | * |
| 2535 | * @param userHandle the userId of the profile to check the password for. |
| 2536 | * @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] | 2537 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2538 | * @hide |
| 2539 | */ |
| 2540 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2541 | if (mService != null) { |
| 2542 | try { |
| 2543 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2544 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2545 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | return false; |
| 2549 | } |
| 2550 | |
| 2551 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2552 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2553 | * successful password entry. |
| 2554 | * <p> |
| 2555 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2556 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2557 | * password attemts for the parent user. |
| 2558 | * <p> |
| 2559 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2560 | * 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] | 2561 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2562 | * @return The number of times user has entered an incorrect password since the last correct |
| 2563 | * password entry. |
| 2564 | * @throws SecurityException if the calling application does not own an active administrator |
| 2565 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2566 | */ |
| 2567 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2568 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2569 | } |
| 2570 | |
| 2571 | /** |
| 2572 | * Retrieve the number of times the given user has failed at entering a |
| 2573 | * password since that last successful password entry. |
| 2574 | * |
| 2575 | * <p>The calling device admin must have requested |
| 2576 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2577 | * not and it is not the system uid, a security exception will be thrown. |
| 2578 | * |
| 2579 | * @hide |
| 2580 | */ |
| 2581 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2582 | if (mService != null) { |
| 2583 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2584 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2585 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2586 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | return -1; |
| 2590 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2591 | |
| 2592 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2593 | * 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] | 2594 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2595 | * @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] | 2596 | * @hide |
| 2597 | */ |
| 2598 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2599 | if (mService != null) { |
| 2600 | try { |
| 2601 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2602 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2603 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2604 | } |
| 2605 | } |
| 2606 | return false; |
| 2607 | } |
| 2608 | |
| 2609 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2610 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2611 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2612 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2613 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2614 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2615 | * <p> |
| 2616 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2617 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2618 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2619 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2620 | * immediately, and your callback will not be invoked. |
| 2621 | * <p> |
| 2622 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2623 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2624 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2625 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2626 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2627 | * @param num The number of failed password attempts at which point the device or profile will |
| 2628 | * be wiped. |
| 2629 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2630 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2631 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2632 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2633 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2634 | if (mService != null) { |
| 2635 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2636 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2637 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2638 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2639 | } |
| 2640 | } |
| 2641 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2642 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2643 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2644 | * 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] | 2645 | * 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] | 2646 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2647 | * not taken into account. |
| 2648 | * |
| 2649 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2650 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2651 | * the value for the parent profile. |
| 2652 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2653 | * @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] | 2654 | * all admins. |
| 2655 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2656 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2657 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2661 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2662 | if (mService != null) { |
| 2663 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2664 | return mService.getMaximumFailedPasswordsForWipe( |
| 2665 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2666 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2667 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | return 0; |
| 2671 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2672 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2673 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2674 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2675 | * for the given user. So for primary user, it might return the primary or |
| 2676 | * a managed profile. For a secondary user, it would be the same as the |
| 2677 | * user passed in. |
| 2678 | * @hide Used only by Keyguard |
| 2679 | */ |
| 2680 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2681 | if (mService != null) { |
| 2682 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2683 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2684 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2685 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2686 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | return UserHandle.USER_NULL; |
| 2690 | } |
| 2691 | |
| 2692 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2693 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2694 | * the password again until the user has entered it. |
| 2695 | */ |
| 2696 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2697 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2698 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2699 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2700 | * If the flag is set, the device can be booted without asking for user password. |
| 2701 | * The absence of this flag does not change the current boot requirements. This flag |
| 2702 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2703 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2704 | * device to factory defaults. |
| 2705 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2706 | 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] | 2707 | |
| 2708 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2709 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2710 | * individual accounts) on the user. This takes effect immediately. |
| 2711 | * <p> |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2712 | * <em>For device owner and profile owners targeting SDK level |
| 2713 | * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will |
| 2714 | * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken} |
| 2715 | * instead. </em> |
| 2716 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2717 | * <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] | 2718 | * device admins that are not device owner and not profile owner. |
| 2719 | * 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] | 2720 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2721 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2722 | * <p> |
| 2723 | * The given password must be sufficient for the current password quality and length constraints |
| 2724 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2725 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2726 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2727 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2728 | * case the currently active quality will be increased to match. |
| 2729 | * <p> |
| 2730 | * 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] | 2731 | * current password constraints allow it. <em>Note: This will not work in |
| 2732 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2733 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2734 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2735 | * <p> |
| 2736 | * The calling device admin must have requested |
| 2737 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2738 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2739 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2740 | * @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] | 2741 | * @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] | 2742 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2743 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2744 | * current constraints or if the user has not been decrypted yet. |
| 2745 | * @throws SecurityException if the calling application does not own an active administrator |
| 2746 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2747 | * @throws IllegalStateException if the calling user is locked or has a managed profile. |
Andrew Scull | 3f81f4e | 2016-07-29 16:29:58 +0100 | [diff] [blame] | 2748 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2749 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2750 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2751 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2752 | if (mService != null) { |
| 2753 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2754 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2755 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2756 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | return false; |
| 2760 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2761 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2762 | /** |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2763 | * Called by a profile or device owner to provision a token which can later be used to reset the |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2764 | * device lockscreen password (if called by device owner), or managed profile challenge (if |
| 2765 | * called by profile owner), via {@link #resetPasswordWithToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2766 | * <p> |
| 2767 | * If the user currently has a lockscreen password, the provisioned token will not be |
| 2768 | * immediately usable; it only becomes active after the user performs a confirm credential |
| 2769 | * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 2770 | * If the user has no lockscreen password, the token is activated immediately. In all cases, |
| 2771 | * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}. |
| 2772 | * For security reasons, un-activated tokens are only stored in memory and will be lost once |
| 2773 | * the device reboots. In this case a new token needs to be provisioned again. |
| 2774 | * <p> |
| 2775 | * Once provisioned and activated, the token will remain effective even if the user changes |
| 2776 | * or clears the lockscreen password. |
| 2777 | * <p> |
| 2778 | * <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] | 2779 | * credentials. In particular, NEVER store this token on device in plaintext. Do not store |
| 2780 | * the plaintext token in device-encrypted storage if it will be needed to reset password on |
| 2781 | * file-based encryption devices before user unlocks. Consider carefully how any password token |
| 2782 | * will be stored on your server and who will need access to them. Tokens may be the subject of |
| 2783 | * legal access requests. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2784 | * </em> |
| 2785 | * |
| 2786 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2787 | * @param token a secure token a least 32-byte long, which must be generated by a |
| 2788 | * cryptographically strong random number generator. |
| 2789 | * @return true if the operation is successful, false otherwise. |
| 2790 | * @throws IllegalArgumentException if the supplied token is invalid. |
| 2791 | * @throws SecurityException |
| 2792 | */ |
| 2793 | public boolean setResetPasswordToken(ComponentName admin, byte[] token) { |
| 2794 | throwIfParentInstance("setResetPasswordToken"); |
| 2795 | if (mService != null) { |
| 2796 | try { |
| 2797 | return mService.setResetPasswordToken(admin, token); |
| 2798 | } catch (RemoteException e) { |
| 2799 | throw e.rethrowFromSystemServer(); |
| 2800 | } |
| 2801 | } |
| 2802 | return false; |
| 2803 | } |
| 2804 | |
| 2805 | /** |
| 2806 | * Called by a profile or device owner to revoke the current password reset token. |
| 2807 | * |
| 2808 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2809 | * @return true if the operation is successful, false otherwise. |
| 2810 | */ |
| 2811 | public boolean clearResetPasswordToken(ComponentName admin) { |
| 2812 | throwIfParentInstance("clearResetPasswordToken"); |
| 2813 | if (mService != null) { |
| 2814 | try { |
| 2815 | return mService.clearResetPasswordToken(admin); |
| 2816 | } catch (RemoteException e) { |
| 2817 | throw e.rethrowFromSystemServer(); |
| 2818 | } |
| 2819 | } |
| 2820 | return false; |
| 2821 | } |
| 2822 | |
| 2823 | /** |
| 2824 | * Called by a profile or device owner to check if the current reset password token is active. |
| 2825 | * |
| 2826 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2827 | * @return true if the token is active, false otherwise. |
| 2828 | * @throws IllegalStateException if no token has been set. |
| 2829 | */ |
| 2830 | public boolean isResetPasswordTokenActive(ComponentName admin) { |
| 2831 | throwIfParentInstance("isResetPasswordTokenActive"); |
| 2832 | if (mService != null) { |
| 2833 | try { |
| 2834 | return mService.isResetPasswordTokenActive(admin); |
| 2835 | } catch (RemoteException e) { |
| 2836 | throw e.rethrowFromSystemServer(); |
| 2837 | } |
| 2838 | } |
| 2839 | return false; |
| 2840 | } |
| 2841 | |
| 2842 | /** |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2843 | * Called by device or profile owner to force set a new device unlock password or a managed |
| 2844 | * profile challenge on current user. This takes effect immediately. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2845 | * <p> |
| 2846 | * Unlike {@link #resetPassword}, this API can change the password even before the user or |
| 2847 | * device is unlocked or decrypted. The supplied token must have been previously provisioned via |
| 2848 | * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}. |
| 2849 | * <p> |
| 2850 | * The given password must be sufficient for the current password quality and length constraints |
| 2851 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2852 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2853 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2854 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2855 | * case the currently active quality will be increased to match. |
| 2856 | * <p> |
| 2857 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
| 2858 | * current password constraints allow it. |
| 2859 | * |
| 2860 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2861 | * @param password The new password for the user. Null or empty clears the password. |
| 2862 | * @param token the password reset token previously provisioned by #setResetPasswordToken. |
| 2863 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
| 2864 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2865 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2866 | * current constraints. |
| 2867 | * @throws SecurityException if the calling application does not own an active administrator |
| 2868 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
| 2869 | * @throws IllegalStateException if the provided token is not valid. |
| 2870 | * @throws IllegalArgumentException if the password does not meet system requirements. |
| 2871 | */ |
| 2872 | public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password, |
| 2873 | byte[] token, int flags) { |
| 2874 | throwIfParentInstance("resetPassword"); |
| 2875 | if (mService != null) { |
| 2876 | try { |
| 2877 | return mService.resetPasswordWithToken(admin, password, token, flags); |
| 2878 | } catch (RemoteException e) { |
| 2879 | throw e.rethrowFromSystemServer(); |
| 2880 | } |
| 2881 | } |
| 2882 | return false; |
| 2883 | } |
| 2884 | |
| 2885 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2886 | * Called by an application that is administering the device to set the maximum time for user |
| 2887 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2888 | * effect immediately. |
| 2889 | * <p> |
| 2890 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2891 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2892 | * <p> |
| 2893 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2894 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2895 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2896 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2897 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2898 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2899 | * is no restriction. |
| 2900 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2901 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2902 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2903 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2904 | if (mService != null) { |
| 2905 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2906 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2907 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2908 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2909 | } |
| 2910 | } |
| 2911 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2912 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2913 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2914 | * 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] | 2915 | * 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] | 2916 | * a separate challenge are not taken into account. |
| 2917 | * |
| 2918 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2919 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2920 | * restrictions on the parent profile. |
| 2921 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2922 | * @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] | 2923 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2924 | * @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] | 2925 | * 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] | 2926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2927 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2928 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2932 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2933 | if (mService != null) { |
| 2934 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2935 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2936 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2937 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2938 | } |
| 2939 | } |
| 2940 | return 0; |
| 2941 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2942 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2943 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2944 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2945 | * do not have a separate timeout to lock for work challenge only. |
| 2946 | * |
| 2947 | * @hide |
| 2948 | */ |
| 2949 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2950 | if (mService != null) { |
| 2951 | try { |
| 2952 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2953 | } catch (RemoteException e) { |
| 2954 | throw e.rethrowFromSystemServer(); |
| 2955 | } |
| 2956 | } |
| 2957 | return 0; |
| 2958 | } |
| 2959 | |
| 2960 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2961 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2962 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2963 | * authentication method like password, pin or pattern. |
| 2964 | * |
| 2965 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2966 | * specified timeout each time it has been successfully used. |
| 2967 | * |
| 2968 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2969 | * |
| 2970 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2971 | * |
| 2972 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2973 | * a {@link SecurityException} will be thrown. |
| 2974 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2975 | * <p>The calling device admin can verify the value it has set by calling |
| 2976 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2977 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2978 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2979 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2980 | * profile. |
| 2981 | * |
| 2982 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 2983 | * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock |
| 2984 | * with strong authentication method. A value of 0 means the admin is not participating |
| 2985 | * in controlling the timeout. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2986 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2987 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2988 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2989 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2990 | * |
| 2991 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2992 | */ |
| 2993 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2994 | long timeoutMs) { |
| 2995 | if (mService != null) { |
| 2996 | try { |
| 2997 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2998 | } catch (RemoteException e) { |
| 2999 | throw e.rethrowFromSystemServer(); |
| 3000 | } |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 3006 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 3007 | * After the returned timeout the user is required to use strong authentication method. |
| 3008 | * |
| 3009 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3010 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3011 | * restrictions on the parent profile. |
| 3012 | * |
| 3013 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 3014 | * accross all participating admins. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3015 | * @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] | 3016 | */ |
| 3017 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 3018 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 3019 | } |
| 3020 | |
| 3021 | /** @hide per-user version */ |
| 3022 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 3023 | if (mService != null) { |
| 3024 | try { |
| 3025 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 3026 | } catch (RemoteException e) { |
| 3027 | throw e.rethrowFromSystemServer(); |
| 3028 | } |
| 3029 | } |
| 3030 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 3031 | } |
| 3032 | |
| 3033 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3034 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 3035 | * keyring. The user's credential will need to be entered again in order to derive the |
| 3036 | * credential encryption key that will be stored back in the keyring for future use. |
| 3037 | * <p> |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3038 | * This flag can only be used by a profile owner when locking a managed profile when |
| 3039 | * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3040 | * <p> |
| 3041 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 3042 | * until they are next run to perform further actions. |
| 3043 | */ |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3044 | public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1; |
| 3045 | |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3046 | /** @hide */ |
| 3047 | @Retention(RetentionPolicy.SOURCE) |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3048 | @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}) |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3049 | public @interface LockNowFlag {} |
| 3050 | |
| 3051 | /** |
| 3052 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3053 | * this call. |
| 3054 | * <p> |
| 3055 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3056 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3057 | * <p> |
| 3058 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3059 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 3060 | * <p> |
| 3061 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 3062 | * |
| 3063 | * @throws SecurityException if the calling application does not own an active administrator |
| 3064 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3065 | */ |
| 3066 | public void lockNow() { |
| 3067 | lockNow(0); |
| 3068 | } |
| 3069 | |
| 3070 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3071 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3072 | * this call. |
| 3073 | * <p> |
| 3074 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3075 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3076 | * <p> |
| 3077 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3078 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3079 | * |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3080 | * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3081 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3082 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3083 | * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application |
| 3084 | * that is not a profile |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3085 | * owner of a managed profile. |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3086 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is |
| 3087 | * passed when locking the parent profile. |
| 3088 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} |
| 3089 | * flag is passed when {@link #getStorageEncryptionStatus} does not return |
| 3090 | * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3091 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3092 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3093 | if (mService != null) { |
| 3094 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3095 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3096 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3097 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3098 | } |
| 3099 | } |
| 3100 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3101 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3102 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3103 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3104 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3105 | */ |
| 3106 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 3107 | |
| 3108 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3109 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 3110 | * data. |
| 3111 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 3112 | * <p>This flag may only be set by device owner admins; if it is set by |
| 3113 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3114 | */ |
| 3115 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 3116 | |
| 3117 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 3118 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3119 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 3120 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 3121 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3122 | * <p> |
| 3123 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3124 | * 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] | 3125 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3126 | * @param flags Bit mask of additional options: currently supported flags are |
| 3127 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3128 | * @throws SecurityException if the calling application does not own an active administrator |
| 3129 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3130 | */ |
| 3131 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3132 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3133 | if (mService != null) { |
| 3134 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3135 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3136 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3137 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3141 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3142 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3143 | * Called by an application that is administering the device to set the |
| 3144 | * global proxy and exclusion list. |
| 3145 | * <p> |
| 3146 | * The calling device admin must have requested |
| 3147 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3148 | * this method; if it has not, a security exception will be thrown. |
| 3149 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3150 | * 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] | 3151 | * 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] | 3152 | * be returned. |
| 3153 | * The method can be called repeatedly by the device admin alrady setting the |
| 3154 | * proxy to update the proxy and exclusion list. |
| 3155 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3156 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3157 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3158 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3159 | * @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] | 3160 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3161 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3162 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3163 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3164 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3165 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3166 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3167 | if (proxySpec == null) { |
| 3168 | throw new NullPointerException(); |
| 3169 | } |
| 3170 | if (mService != null) { |
| 3171 | try { |
| 3172 | String hostSpec; |
| 3173 | String exclSpec; |
| 3174 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3175 | hostSpec = null; |
| 3176 | exclSpec = null; |
| 3177 | } else { |
| 3178 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3179 | throw new IllegalArgumentException(); |
| 3180 | } |
| 3181 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3182 | String hostName = sa.getHostName(); |
| 3183 | int port = sa.getPort(); |
| 3184 | StringBuilder hostBuilder = new StringBuilder(); |
| 3185 | hostSpec = hostBuilder.append(hostName) |
| 3186 | .append(":").append(Integer.toString(port)).toString(); |
| 3187 | if (exclusionList == null) { |
| 3188 | exclSpec = ""; |
| 3189 | } else { |
| 3190 | StringBuilder listBuilder = new StringBuilder(); |
| 3191 | boolean firstDomain = true; |
| 3192 | for (String exclDomain : exclusionList) { |
| 3193 | if (!firstDomain) { |
| 3194 | listBuilder = listBuilder.append(","); |
| 3195 | } else { |
| 3196 | firstDomain = false; |
| 3197 | } |
| 3198 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3199 | } |
| 3200 | exclSpec = listBuilder.toString(); |
| 3201 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3202 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3203 | != android.net.Proxy.PROXY_VALID) |
| 3204 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3205 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3206 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3207 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3208 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3209 | } |
| 3210 | } |
| 3211 | return null; |
| 3212 | } |
| 3213 | |
| 3214 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3215 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3216 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3217 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3218 | * proxy is not accessible, you may break HTTP using this. |
| 3219 | * <p> |
| 3220 | * This method requires the caller to be the device owner. |
| 3221 | * <p> |
| 3222 | * 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] | 3223 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3224 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3225 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3226 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3227 | * {@code null} value will clear the global HTTP proxy. |
| 3228 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3229 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3230 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3231 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3232 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3233 | if (mService != null) { |
| 3234 | try { |
| 3235 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3236 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3237 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3243 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3244 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3245 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3246 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3247 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3248 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3249 | if (mService != null) { |
| 3250 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3251 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3252 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3253 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3254 | } |
| 3255 | } |
| 3256 | return null; |
| 3257 | } |
| 3258 | |
| 3259 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3260 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3261 | * indicating that encryption is not supported. |
| 3262 | */ |
| 3263 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3264 | |
| 3265 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3266 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3267 | * indicating that encryption is supported, but is not currently active. |
| 3268 | */ |
| 3269 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3270 | |
| 3271 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3272 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3273 | * indicating that encryption is not currently active, but is currently |
| 3274 | * being activated. This is only reported by devices that support |
| 3275 | * encryption of data and only when the storage is currently |
| 3276 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3277 | * to become encrypted will never return this value. |
| 3278 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3279 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3280 | |
| 3281 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3282 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3283 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3284 | * <p> |
| 3285 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3286 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3287 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3288 | |
| 3289 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3290 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3291 | * indicating that encryption is active, but an encryption key has not |
| 3292 | * been set by the user. |
| 3293 | */ |
| 3294 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3295 | |
| 3296 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3297 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3298 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3299 | * <p> |
| 3300 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3301 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3302 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3303 | */ |
| 3304 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3305 | |
| 3306 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3307 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3308 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3309 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3310 | * to check encryption status. However, on some devices this activity may never return, as |
| 3311 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3312 | */ |
| 3313 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3314 | public static final String ACTION_START_ENCRYPTION |
| 3315 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3316 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3317 | * Widgets are enabled in keyguard |
| 3318 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3319 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3320 | |
| 3321 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3322 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3323 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3324 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3325 | |
| 3326 | /** |
| 3327 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3328 | */ |
| 3329 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3330 | |
| 3331 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3332 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3333 | */ |
| 3334 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3335 | |
| 3336 | /** |
| 3337 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3338 | */ |
| 3339 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3340 | |
| 3341 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3342 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3343 | * (e.g. PIN/Pattern/Password). |
| 3344 | */ |
| 3345 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3346 | |
| 3347 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3348 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3349 | */ |
| 3350 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3351 | |
| 3352 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3353 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3354 | */ |
| 3355 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3356 | |
| 3357 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3358 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3359 | */ |
| 3360 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3361 | |
| 3362 | /** |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3363 | * Keyguard features that when set on a managed profile that doesn't have its own challenge will |
| 3364 | * affect the profile's parent user. These can also be set on the managed profile's parent |
| 3365 | * {@link DevicePolicyManager} instance. |
| 3366 | * |
| 3367 | * @hide |
| 3368 | */ |
| 3369 | public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER = |
| 3370 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS |
| 3371 | | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT; |
| 3372 | |
| 3373 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3374 | * Called by an application that is administering the device to request that the storage system |
| 3375 | * be encrypted. |
| 3376 | * <p> |
| 3377 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3378 | * supported setting will always be used. If any device administrator requests device |
| 3379 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3380 | * 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] | 3381 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3382 | * <p> |
| 3383 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3384 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3385 | * control the encryption of any other storage areas. There is one exception: If |
| 3386 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3387 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3388 | * written to disk within the encrypted storage area. |
| 3389 | * <p> |
| 3390 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3391 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3392 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3393 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3394 | * |
| 3395 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3396 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3397 | * @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] | 3398 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3399 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3400 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3401 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3402 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3403 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3404 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3405 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3406 | if (mService != null) { |
| 3407 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3408 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3409 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3410 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3411 | } |
| 3412 | } |
| 3413 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3414 | } |
| 3415 | |
| 3416 | /** |
| 3417 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3418 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3419 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3420 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3421 | * this will return the requested encryption setting as an aggregate of all active |
| 3422 | * administrators. |
| 3423 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3424 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3425 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3426 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3427 | if (mService != null) { |
| 3428 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3429 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3430 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3431 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3432 | } |
| 3433 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3434 | return false; |
| 3435 | } |
| 3436 | |
| 3437 | /** |
| 3438 | * Called by an application that is administering the device to |
| 3439 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3440 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3441 | * Depending on the returned status code, the caller may proceed in different |
| 3442 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3443 | * storage system does not support encryption. If the |
| 3444 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3445 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3446 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3447 | * 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] | 3448 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3449 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3450 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3451 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3452 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3453 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3454 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3455 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3456 | */ |
| 3457 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3458 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3459 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | /** @hide per-user version */ |
| 3463 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3464 | if (mService != null) { |
| 3465 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3466 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3467 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3468 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3469 | } |
| 3470 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3471 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3472 | } |
| 3473 | |
| 3474 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3475 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3476 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3477 | * keep the certificate on the device. |
| 3478 | * |
| 3479 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3480 | * this certificate. |
| 3481 | * |
| 3482 | * @hide |
| 3483 | */ |
| 3484 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3485 | if (mService != null) { |
| 3486 | try { |
| 3487 | return mService.approveCaCert(alias, userHandle, approval); |
| 3488 | } catch (RemoteException e) { |
| 3489 | throw e.rethrowFromSystemServer(); |
| 3490 | } |
| 3491 | } |
| 3492 | return false; |
| 3493 | } |
| 3494 | |
| 3495 | /** |
| 3496 | * Check whether a CA certificate has been approved by the device user. |
| 3497 | * |
| 3498 | * @hide |
| 3499 | */ |
| 3500 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3501 | if (mService != null) { |
| 3502 | try { |
| 3503 | return mService.isCaCertApproved(alias, userHandle); |
| 3504 | } catch (RemoteException e) { |
| 3505 | throw e.rethrowFromSystemServer(); |
| 3506 | } |
| 3507 | } |
| 3508 | return false; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3512 | * Installs the given certificate as a user CA. |
| 3513 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3514 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3515 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3516 | * security exception will be thrown. |
| 3517 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3518 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3519 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3520 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3521 | * |
| 3522 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3523 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3524 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3525 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3526 | * @see #setDelegatedScopes |
| 3527 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3528 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3529 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3530 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3531 | if (mService != null) { |
| 3532 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3533 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3534 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3535 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3536 | } |
| 3537 | } |
| 3538 | return false; |
| 3539 | } |
| 3540 | |
| 3541 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3542 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3543 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3544 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3545 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3546 | * security exception will be thrown. |
| 3547 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3548 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3549 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3550 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3551 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3552 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3553 | * @see #setDelegatedScopes |
| 3554 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3555 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3556 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3557 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3558 | if (mService != null) { |
| 3559 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3560 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3561 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3562 | } catch (CertificateException e) { |
| 3563 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3564 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3565 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3566 | } |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3571 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3572 | * If a user has installed any certificates by other means than device policy these will be |
| 3573 | * included too. |
| 3574 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3575 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3576 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3577 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3578 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3579 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3580 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3581 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3582 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3583 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3584 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3585 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3586 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3587 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3588 | for (String alias : certStore.userAliases()) { |
| 3589 | try { |
| 3590 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3591 | } catch (CertificateException ce) { |
| 3592 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3593 | } |
| 3594 | } |
| 3595 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3596 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3603 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3604 | * means other than device policy will also be removed, except for system CA certificates. |
| 3605 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3606 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3607 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3608 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3609 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3610 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3611 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3612 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3613 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3614 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3615 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3616 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3617 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3618 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3619 | } |
| 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | /** |
| 3624 | * Returns whether this certificate is installed as a trusted CA. |
| 3625 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3626 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3627 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3628 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3629 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3630 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3631 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3632 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3633 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3634 | if (mService != null) { |
| 3635 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3636 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3637 | return getCaCertAlias(certBuffer) != null; |
| 3638 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3639 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3640 | } catch (CertificateException ce) { |
| 3641 | Log.w(TAG, "Could not parse certificate", ce); |
| 3642 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3643 | } |
| 3644 | return false; |
| 3645 | } |
| 3646 | |
| 3647 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3648 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3649 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3650 | * the certificate and use the private key, given direct user approval. |
| 3651 | * |
| 3652 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3653 | * direct user approval. This is for security - should a certificate installer become |
| 3654 | * compromised, certificates it had already installed will be protected. |
| 3655 | * |
| 3656 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3657 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3658 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3659 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3660 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3661 | * @param privKey The private key to install. |
| 3662 | * @param cert The certificate to install. |
| 3663 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3664 | * with that alias already exists, it will be overwritten. |
| 3665 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3666 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3667 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3668 | * @see #setDelegatedScopes |
| 3669 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3670 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3671 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3672 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3673 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | /** |
| 3677 | * 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] | 3678 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3679 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3680 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3681 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3682 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3683 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3684 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3685 | * |
| 3686 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3687 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3688 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3689 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3690 | * certificate and include the chain of trust in order. This will be returned by |
| 3691 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3692 | * @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] | 3693 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3694 | * @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] | 3695 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3696 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3697 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3698 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3699 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3700 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3701 | * @see #setDelegatedScopes |
| 3702 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3703 | */ |
| 3704 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3705 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3706 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3707 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3708 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3709 | byte[] pemChain = null; |
| 3710 | if (certs.length > 1) { |
| 3711 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3712 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3713 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3714 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3715 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3716 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3717 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3718 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3719 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3720 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3721 | } catch (CertificateException | IOException e) { |
| 3722 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3723 | } |
| 3724 | return false; |
| 3725 | } |
| 3726 | |
| 3727 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3728 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3729 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3730 | * |
| 3731 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3732 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3733 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3734 | * @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] | 3735 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3736 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3737 | * @see #setDelegatedScopes |
| 3738 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3739 | */ |
| 3740 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3741 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3742 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3743 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3744 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3745 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3746 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3750 | * @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] | 3751 | * doesn't exist. |
| 3752 | */ |
| 3753 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3754 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3755 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3756 | new ByteArrayInputStream(certBuffer)); |
| 3757 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3758 | } |
| 3759 | |
| 3760 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3761 | * 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] | 3762 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3763 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3764 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3765 | * <p> |
| 3766 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3767 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3768 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3769 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3770 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3771 | * 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] | 3772 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3773 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3774 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3775 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3776 | * @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] | 3777 | * access. If {@code null} is given the current package will be cleared. |
| 3778 | * @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] | 3779 | * |
| 3780 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 3781 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3782 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3783 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3784 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3785 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3786 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3787 | if (mService != null) { |
| 3788 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3789 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3790 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3791 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3792 | } |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3797 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3798 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3799 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3800 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3801 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3802 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3803 | * none is set. |
| 3804 | * @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] | 3805 | * |
| 3806 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3807 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3808 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3809 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3810 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3811 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3812 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3813 | if (mService != null) { |
| 3814 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3815 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3816 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3817 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3818 | } |
| 3819 | } |
| 3820 | return null; |
| 3821 | } |
| 3822 | |
| 3823 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3824 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3825 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3826 | * constants. |
| 3827 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3828 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 3829 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 3830 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 3831 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 3832 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3833 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3834 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3835 | * {@code delegatePackage}. |
| 3836 | * |
| 3837 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3838 | * @param delegatePackage The package name of the app which will be given access. |
| 3839 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3840 | * {@code delegatedPackage}. |
| 3841 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3842 | */ |
| 3843 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3844 | @NonNull List<String> scopes) { |
| 3845 | throwIfParentInstance("setDelegatedScopes"); |
| 3846 | if (mService != null) { |
| 3847 | try { |
| 3848 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 3849 | } catch (RemoteException e) { |
| 3850 | throw e.rethrowFromSystemServer(); |
| 3851 | } |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | /** |
| 3856 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 3857 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 3858 | * passing {@code null} for {@code admin} and their own package name as |
| 3859 | * {@code delegatedPackage}. |
| 3860 | * |
| 3861 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3862 | * {@code null} if the caller is {@code delegatedPackage}. |
| 3863 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 3864 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 3865 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3866 | */ |
| 3867 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3868 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3869 | @NonNull String delegatedPackage) { |
| 3870 | throwIfParentInstance("getDelegatedScopes"); |
| 3871 | if (mService != null) { |
| 3872 | try { |
| 3873 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 3874 | } catch (RemoteException e) { |
| 3875 | throw e.rethrowFromSystemServer(); |
| 3876 | } |
| 3877 | } |
| 3878 | return null; |
| 3879 | } |
| 3880 | |
| 3881 | /** |
| 3882 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 3883 | * granted a delegation scope. |
| 3884 | * |
| 3885 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3886 | * @param delegationScope The scope whose delegates should be retrieved. |
| 3887 | * @return A list of package names of the current delegated packages for |
| 3888 | {@code delegationScope}. |
| 3889 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3890 | */ |
| 3891 | @Nullable |
| 3892 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 3893 | @NonNull String delegationScope) { |
| 3894 | throwIfParentInstance("getDelegatePackages"); |
| 3895 | if (mService != null) { |
| 3896 | try { |
| 3897 | return mService.getDelegatePackages(admin, delegationScope); |
| 3898 | } catch (RemoteException e) { |
| 3899 | throw e.rethrowFromSystemServer(); |
| 3900 | } |
| 3901 | } |
| 3902 | return null; |
| 3903 | } |
| 3904 | |
| 3905 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3906 | * Called by a device or profile owner to configure an always-on VPN connection through a |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3907 | * specific application for the current user. |
| 3908 | * |
| 3909 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3910 | * TODO: delete once there are no longer any live references. |
| 3911 | * @hide |
| 3912 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3913 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3914 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3915 | throws NameNotFoundException, UnsupportedOperationException { |
| 3916 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3917 | } |
| 3918 | |
| 3919 | /** |
| 3920 | * 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] | 3921 | * specific application for the current user. This connection is automatically granted and |
| 3922 | * persisted after a reboot. |
| 3923 | * <p> |
| 3924 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3925 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3926 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3927 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3928 | * @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] | 3929 | * remove an existing always-on VPN configuration. |
| 3930 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3931 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3932 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3933 | * @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] | 3934 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3935 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3936 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3937 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3938 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3939 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3940 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3941 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3942 | if (mService != null) { |
| 3943 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3944 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3945 | throw new NameNotFoundException(vpnPackage); |
| 3946 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3947 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3948 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3949 | } |
| 3950 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | /** |
| 3954 | * 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] | 3955 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3956 | * 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] | 3957 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3958 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3959 | * is set. |
| 3960 | * @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] | 3961 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3962 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3963 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3964 | if (mService != null) { |
| 3965 | try { |
| 3966 | return mService.getAlwaysOnVpnPackage(admin); |
| 3967 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3968 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3969 | } |
| 3970 | } |
| 3971 | return null; |
| 3972 | } |
| 3973 | |
| 3974 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3975 | * Called by an application that is administering the device to disable all cameras on the |
| 3976 | * device, for this user. After setting this, no applications running as this user will be able |
| 3977 | * to access any cameras on the device. |
| 3978 | * <p> |
| 3979 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3980 | * <p> |
| 3981 | * The calling device admin must have requested |
| 3982 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3983 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3984 | * |
| 3985 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3986 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3987 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3988 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3989 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3990 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3991 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3992 | if (mService != null) { |
| 3993 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3994 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3995 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3996 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3997 | } |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4002 | * 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] | 4003 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4004 | * @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] | 4005 | * have disabled the camera |
| 4006 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4007 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4008 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4009 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4013 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4014 | if (mService != null) { |
| 4015 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4016 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4017 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4018 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4019 | } |
| 4020 | } |
| 4021 | return false; |
| 4022 | } |
| 4023 | |
| 4024 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4025 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4026 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 4027 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 4028 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 4029 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4030 | * |
| 4031 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4032 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 4033 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 4034 | * 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] | 4035 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 4036 | * 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] | 4037 | */ |
| 4038 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4039 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4040 | if (mService != null) { |
| 4041 | try { |
| 4042 | return mService.requestBugreport(admin); |
| 4043 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4044 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4045 | } |
| 4046 | } |
| 4047 | return false; |
| 4048 | } |
| 4049 | |
| 4050 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 4051 | * Determine whether or not creating a guest user has been disabled for the device |
| 4052 | * |
| 4053 | * @hide |
| 4054 | */ |
| 4055 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 4056 | // Currently guest users can always be created if multi-user is enabled |
| 4057 | // TODO introduce a policy for guest user creation |
| 4058 | return false; |
| 4059 | } |
| 4060 | |
| 4061 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 4062 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 4063 | * screen capture also prevents the content from being shown on display devices that do not have |
| 4064 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 4065 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4066 | * <p> |
| 4067 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4068 | * exception will be thrown. |
| 4069 | * <p> |
| 4070 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 4071 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 4072 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4073 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4074 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4075 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4076 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4077 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4078 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4079 | if (mService != null) { |
| 4080 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4081 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4082 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4083 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4084 | } |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4089 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4090 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4091 | * @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] | 4092 | * have disabled screen capture. |
| 4093 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4094 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4095 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4096 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4100 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4101 | if (mService != null) { |
| 4102 | try { |
| 4103 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 4104 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4105 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4106 | } |
| 4107 | } |
| 4108 | return false; |
| 4109 | } |
| 4110 | |
| 4111 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4112 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 4113 | * 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] | 4114 | * <p> |
| 4115 | * Note: if auto time is required the user can still manually set the time zone. |
| 4116 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4117 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4118 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4119 | * |
| 4120 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4121 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4122 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4123 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4124 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4125 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4126 | if (mService != null) { |
| 4127 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4128 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4129 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4130 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4131 | } |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | /** |
| 4136 | * @return true if auto time is required. |
| 4137 | */ |
| 4138 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4139 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4140 | if (mService != null) { |
| 4141 | try { |
| 4142 | return mService.getAutoTimeRequired(); |
| 4143 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4144 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4145 | } |
| 4146 | } |
| 4147 | return false; |
| 4148 | } |
| 4149 | |
| 4150 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4151 | * 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] | 4152 | * <p> |
| 4153 | * The system user is exempt from this policy - it is never ephemeral. |
| 4154 | * <p> |
| 4155 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4156 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4157 | * |
| 4158 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4159 | * @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] | 4160 | * subsequently created users will be ephemeral. |
| 4161 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4162 | * @hide |
| 4163 | */ |
| 4164 | public void setForceEphemeralUsers( |
| 4165 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4166 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4167 | if (mService != null) { |
| 4168 | try { |
| 4169 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 4170 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4171 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4172 | } |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | /** |
| 4177 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4178 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4179 | * @hide |
| 4180 | */ |
| 4181 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4182 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4183 | if (mService != null) { |
| 4184 | try { |
| 4185 | return mService.getForceEphemeralUsers(admin); |
| 4186 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4187 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4188 | } |
| 4189 | } |
| 4190 | return false; |
| 4191 | } |
| 4192 | |
| 4193 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4194 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4195 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4196 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4197 | * <p> |
| 4198 | * The calling device admin must have requested |
| 4199 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4200 | * if it has not, a security exception will be thrown. |
| 4201 | * <p> |
| 4202 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4203 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4204 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4205 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4206 | * <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] | 4207 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4208 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4209 | * there is one, or the parent user otherwise. |
| 4210 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4211 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4212 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4213 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4214 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4215 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4216 | * profile. |
| 4217 | * <p> |
| 4218 | * Requests to disable other features on a managed profile will be ignored. |
| 4219 | * <p> |
| 4220 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4221 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4222 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4223 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4224 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4225 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4226 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4227 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4228 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4229 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4230 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4231 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4232 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4233 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4234 | if (mService != null) { |
| 4235 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4236 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4237 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4238 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4239 | } |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4244 | * 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] | 4245 | * 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] | 4246 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4247 | * |
| 4248 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4249 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4250 | * restrictions on the parent profile. |
| 4251 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4252 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4253 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4254 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4255 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4256 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4257 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4258 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4262 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4263 | if (mService != null) { |
| 4264 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4265 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4266 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4267 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4268 | } |
| 4269 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4270 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4274 | * @hide |
| 4275 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4276 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4277 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4278 | if (mService != null) { |
| 4279 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4280 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4281 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4282 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4283 | } |
| 4284 | } |
| 4285 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4286 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4287 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4288 | * @hide |
| 4289 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4290 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4291 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4295 | * @hide |
| 4296 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4297 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4298 | if (mService != null) { |
| 4299 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4300 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4301 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4302 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4303 | } |
| 4304 | } |
| 4305 | } |
| 4306 | |
| 4307 | /** |
| 4308 | * @hide |
| 4309 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4310 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4311 | if (mService != null) { |
| 4312 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4313 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4314 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4315 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4316 | } |
| 4317 | } |
| 4318 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4319 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4320 | /** |
| 4321 | * @hide |
| 4322 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4323 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4324 | if (mService != null) { |
| 4325 | try { |
| 4326 | mService.reportPasswordChanged(userId); |
| 4327 | } catch (RemoteException e) { |
| 4328 | throw e.rethrowFromSystemServer(); |
| 4329 | } |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | /** |
| 4334 | * @hide |
| 4335 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4336 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4337 | if (mService != null) { |
| 4338 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4339 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4340 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4341 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4342 | } |
| 4343 | } |
| 4344 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4345 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4346 | /** |
| 4347 | * @hide |
| 4348 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4349 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4350 | if (mService != null) { |
| 4351 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4352 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4353 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4354 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4355 | } |
| 4356 | } |
| 4357 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4358 | |
| 4359 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4360 | * @hide |
| 4361 | */ |
| 4362 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4363 | if (mService != null) { |
| 4364 | try { |
| 4365 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4366 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4367 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4368 | } |
| 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | /** |
| 4373 | * @hide |
| 4374 | */ |
| 4375 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4376 | if (mService != null) { |
| 4377 | try { |
| 4378 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4379 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4380 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4381 | } |
| 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4386 | * Should be called when keyguard has been dismissed. |
| 4387 | * @hide |
| 4388 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4389 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4390 | if (mService != null) { |
| 4391 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4392 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4393 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4394 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4395 | } |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | /** |
| 4400 | * Should be called when keyguard view has been shown to the user. |
| 4401 | * @hide |
| 4402 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4403 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4404 | if (mService != null) { |
| 4405 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4406 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4407 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4408 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4409 | } |
| 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4414 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4415 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4416 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4417 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4418 | * @return whether the package was successfully registered as the device owner. |
| 4419 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4420 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4421 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4422 | public boolean setDeviceOwner(ComponentName who) { |
| 4423 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | /** |
| 4427 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4428 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4429 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4430 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4431 | } |
| 4432 | |
| 4433 | /** |
| 4434 | * @hide |
| 4435 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4436 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4437 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | /** |
| 4441 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4442 | * Sets the given package as the device owner. The package must already be installed. There |
| 4443 | * must not already be a device owner. |
| 4444 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4445 | * this method. |
| 4446 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4447 | * 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] | 4448 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4449 | * @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] | 4450 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4451 | * @return whether the package was successfully registered as the device owner. |
| 4452 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4453 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4454 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4455 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4456 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4457 | if (mService != null) { |
| 4458 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4459 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4460 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4461 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4462 | } |
| 4463 | } |
| 4464 | return false; |
| 4465 | } |
| 4466 | |
| 4467 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4468 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4469 | * 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] | 4470 | * 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] | 4471 | * package is currently registered as the device owner app, pass in the package name from |
| 4472 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4473 | * 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] | 4474 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4475 | * the setup process. |
| 4476 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4477 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4478 | * @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] | 4479 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4480 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4481 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4482 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4483 | } |
| 4484 | |
| 4485 | /** |
| 4486 | * @return true if a package is registered as device owner, only when it's running on the |
| 4487 | * calling user. |
| 4488 | * |
| 4489 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4490 | * @hide |
| 4491 | */ |
| 4492 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4493 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4498 | * user. |
| 4499 | * |
| 4500 | * <p>Requires the MANAGE_USERS permission. |
| 4501 | * |
| 4502 | * @hide |
| 4503 | */ |
| 4504 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4505 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4506 | } |
| 4507 | |
| 4508 | /** |
| 4509 | * @return device owner component name, only when it's running on the calling user. |
| 4510 | * |
| 4511 | * @hide |
| 4512 | */ |
| 4513 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4514 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4515 | } |
| 4516 | |
| 4517 | /** |
| 4518 | * @return device owner component name, even if it's running on a different user. |
| 4519 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4520 | * @hide |
| 4521 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4522 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 4523 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4524 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4525 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4526 | } |
| 4527 | |
| 4528 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4529 | if (packageName == null) { |
| 4530 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4531 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4532 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4533 | if (deviceOwner == null) { |
| 4534 | return false; |
| 4535 | } |
| 4536 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4537 | } |
| 4538 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4539 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4540 | if (mService != null) { |
| 4541 | try { |
| 4542 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4543 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4544 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4550 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4551 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4552 | * no device owner. |
| 4553 | * |
| 4554 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4555 | * |
| 4556 | * @hide |
| 4557 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4558 | public int getDeviceOwnerUserId() { |
| 4559 | if (mService != null) { |
| 4560 | try { |
| 4561 | return mService.getDeviceOwnerUserId(); |
| 4562 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4563 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4564 | } |
| 4565 | } |
| 4566 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4570 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4571 | * 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] | 4572 | * a part of device setup, before it completes. |
| 4573 | * <p> |
| 4574 | * While some policies previously set by the device owner will be cleared by this method, it is |
| 4575 | * a best-effort process and some other policies will still remain in place after the device |
| 4576 | * owner is cleared. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4577 | * |
| 4578 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4579 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4580 | * does not own the current device owner component. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4581 | * |
| 4582 | * @deprecated This method is expected to be used for testing purposes only. The device owner |
| 4583 | * will lose control of the device and its data after calling it. In order to protect any |
| 4584 | * sensitive data that remains on the device, it is advised that the device owner factory resets |
| 4585 | * the device instead of calling this method. See {@link #wipeData(int)}. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4586 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4587 | @Deprecated |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4588 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4589 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4590 | if (mService != null) { |
| 4591 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4592 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4593 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4594 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | } |
| 4598 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4599 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4600 | * Returns the device owner package name, only if it's running on the calling user. |
| 4601 | * |
| 4602 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4603 | * |
| 4604 | * @hide |
| 4605 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4606 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 4607 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4608 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4609 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4610 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4611 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4615 | * 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] | 4616 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4617 | * @return whether the device is managed by a Device Owner. |
| 4618 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4619 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4620 | * |
| 4621 | * @hide |
| 4622 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4623 | @SystemApi |
| 4624 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 4625 | @SuppressLint("Doclava125") |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4626 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4627 | try { |
| 4628 | return mService.hasDeviceOwner(); |
| 4629 | } catch (RemoteException re) { |
| 4630 | throw re.rethrowFromSystemServer(); |
| 4631 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * Returns the device owner name. Note this method *will* return the device owner |
| 4636 | * name when it's running on a different user. |
| 4637 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4638 | * @hide |
| 4639 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4640 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 4641 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4642 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4643 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4644 | if (mService != null) { |
| 4645 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4646 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4647 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4648 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4649 | } |
| 4650 | } |
| 4651 | return null; |
| 4652 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4653 | |
| 4654 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4655 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4656 | * @deprecated Do not use |
| 4657 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4658 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4659 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4660 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4661 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4662 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4663 | return null; |
| 4664 | } |
| 4665 | |
| 4666 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4667 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4668 | * @deprecated Do not use |
| 4669 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4670 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4671 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4672 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4673 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4674 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4675 | return null; |
| 4676 | } |
| 4677 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4678 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4679 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4680 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4681 | * Sets the given component as an active admin and registers the package as the profile |
| 4682 | * owner for this user. The package must already be installed and there shouldn't be |
| 4683 | * an existing profile owner registered for this user. Also, this method must be called |
| 4684 | * before the user setup has been completed. |
| 4685 | * <p> |
| 4686 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4687 | * MANAGE_DEVICE_ADMINS permission. |
| 4688 | * @param admin The component to register as an active admin and profile owner. |
| 4689 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4690 | * @return whether the admin was successfully registered as the profile owner. |
| 4691 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4692 | * the user has already been set up. |
| 4693 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4694 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4695 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4696 | @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4697 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4698 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4699 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4700 | if (mService != null) { |
| 4701 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4702 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4703 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4704 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4705 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4706 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4707 | } |
| 4708 | } |
| 4709 | return false; |
| 4710 | } |
| 4711 | |
| 4712 | /** |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4713 | * Clears the active profile owner. The caller must be the profile owner of this user, otherwise |
| 4714 | * 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] | 4715 | * <p> |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4716 | * While some policies previously set by the profile owner will be cleared by this method, it is |
| 4717 | * a best-effort process and some other policies will still remain in place after the profile |
| 4718 | * owner is cleared. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4719 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4720 | * @param admin The component to remove as the profile owner. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4721 | * @throws SecurityException if {@code admin} is not an active profile owner, or the method is |
| 4722 | * being called from a managed profile. |
| 4723 | * |
| 4724 | * @deprecated This method is expected to be used for testing purposes only. The profile owner |
| 4725 | * will lose control of the user and its data after calling it. In order to protect any |
| 4726 | * sensitive data that remains on this user, it is advised that the profile owner deletes it |
| 4727 | * instead of calling this method. See {@link #wipeData(int)}. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4728 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4729 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4730 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4731 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4732 | if (mService != null) { |
| 4733 | try { |
| 4734 | mService.clearProfileOwner(admin); |
| 4735 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4736 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4737 | } |
| 4738 | } |
| 4739 | } |
| 4740 | |
| 4741 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4742 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4743 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4744 | */ |
| 4745 | public boolean hasUserSetupCompleted() { |
| 4746 | if (mService != null) { |
| 4747 | try { |
| 4748 | return mService.hasUserSetupCompleted(); |
| 4749 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4750 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4751 | } |
| 4752 | } |
| 4753 | return true; |
| 4754 | } |
| 4755 | |
| 4756 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4757 | * @hide |
| 4758 | * 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] | 4759 | * already be installed. There must not already be a profile owner for this user. |
| 4760 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4761 | * this method. |
| 4762 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4763 | * - the caller is SYSTEM_UID. |
| 4764 | * - 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] | 4765 | * @param admin the component name to be registered as profile owner. |
| 4766 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4767 | * @param userHandle the userId to set the profile owner for. |
| 4768 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4769 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4770 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4771 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4772 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4773 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4774 | if (mService != null) { |
| 4775 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4776 | if (ownerName == null) { |
| 4777 | ownerName = ""; |
| 4778 | } |
| 4779 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4780 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4781 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4782 | } |
| 4783 | } |
| 4784 | return false; |
| 4785 | } |
| 4786 | |
| 4787 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4788 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4789 | * <p> |
| 4790 | * 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] | 4791 | * 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] | 4792 | * <p> |
| 4793 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4794 | * will be blank and the user will not be allowed to change it. |
| 4795 | * <p> |
| 4796 | * 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] | 4797 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4798 | * and set a new version of this string accordingly. |
| 4799 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4800 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4801 | * @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] | 4802 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4803 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4804 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4805 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4806 | if (mService != null) { |
| 4807 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4808 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4809 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4810 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4811 | } |
| 4812 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | /** |
| 4816 | * @return The device owner information. If it is not set returns {@code null}. |
| 4817 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4818 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4819 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4820 | if (mService != null) { |
| 4821 | try { |
| 4822 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4823 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4824 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | return null; |
| 4828 | } |
| 4829 | |
| 4830 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4831 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4832 | * called by a device owner, profile owner, or by a delegate given the |
| 4833 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4834 | * <p> |
| 4835 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4836 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4837 | * device. |
| 4838 | * <p> |
| 4839 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4840 | * 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] | 4841 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4842 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4843 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4844 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4845 | * @param packageNames The package names to suspend or unsuspend. |
| 4846 | * @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] | 4847 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4848 | * @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] | 4849 | * this method. |
| 4850 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4851 | * @see #setDelegatedScopes |
| 4852 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4853 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4854 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4855 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4856 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4857 | if (mService != null) { |
| 4858 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4859 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 4860 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4861 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4862 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4863 | } |
| 4864 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4865 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4869 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 4870 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 4871 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4872 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4873 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4874 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4875 | * @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] | 4876 | * @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] | 4877 | * suspended, could not be found or an error occurred. |
| 4878 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4879 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4880 | * @see #setDelegatedScopes |
| 4881 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4882 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4883 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4884 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4885 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4886 | if (mService != null) { |
| 4887 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4888 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4889 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4890 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4891 | } catch (IllegalArgumentException ex) { |
| 4892 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4893 | } |
| 4894 | } |
| 4895 | return false; |
| 4896 | } |
| 4897 | |
| 4898 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4899 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4900 | * be used. Only the profile owner can call this. |
| 4901 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4902 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4903 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4904 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4905 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4906 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4907 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4908 | if (mService != null) { |
| 4909 | try { |
| 4910 | mService.setProfileEnabled(admin); |
| 4911 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4912 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4913 | } |
| 4914 | } |
| 4915 | } |
| 4916 | |
| 4917 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4918 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4919 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4920 | * 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] | 4921 | * |
| 4922 | * @see #isProfileOwnerApp |
| 4923 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4924 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4925 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4926 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4927 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4928 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4929 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4930 | if (mService != null) { |
| 4931 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4932 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4933 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4934 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4935 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4936 | } |
| 4937 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4938 | |
| 4939 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4940 | * 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] | 4941 | * 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] | 4942 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4943 | * |
| 4944 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4945 | * @return Whether or not the package is registered as the profile owner. |
| 4946 | */ |
| 4947 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4948 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4949 | if (mService != null) { |
| 4950 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4951 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4952 | return profileOwner != null |
| 4953 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4954 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4955 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | return false; |
| 4959 | } |
| 4960 | |
| 4961 | /** |
| 4962 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4963 | * @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] | 4964 | * owner has been set for that user. |
| 4965 | * @throws IllegalArgumentException if the userId is invalid. |
| 4966 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4967 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4968 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4969 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4970 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4971 | } |
| 4972 | |
| 4973 | /** |
| 4974 | * @see #getProfileOwner() |
| 4975 | * @hide |
| 4976 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4977 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4978 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4979 | if (mService != null) { |
| 4980 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4981 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4982 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4983 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4984 | } |
| 4985 | } |
| 4986 | return null; |
| 4987 | } |
| 4988 | |
| 4989 | /** |
| 4990 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4991 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4992 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4993 | * @throws IllegalArgumentException if the userId is invalid. |
| 4994 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4995 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4996 | if (mService != null) { |
| 4997 | try { |
| 4998 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4999 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5000 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5001 | } |
| 5002 | } |
| 5003 | return null; |
| 5004 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5005 | |
| 5006 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5007 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5008 | * @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] | 5009 | * @return the human readable name of the organisation associated with this profile owner or |
| 5010 | * null if one is not set. |
| 5011 | * @throws IllegalArgumentException if the userId is invalid. |
| 5012 | */ |
| 5013 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 5014 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5015 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5016 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5017 | if (mService != null) { |
| 5018 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 5019 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5020 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5021 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5022 | } |
| 5023 | } |
| 5024 | return null; |
| 5025 | } |
| 5026 | |
| 5027 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5028 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 5029 | * 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] | 5030 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 5031 | * intent preferences are reset. |
| 5032 | * <p> |
| 5033 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 5034 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 5035 | * the filter. |
| 5036 | * <p> |
| 5037 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 5038 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5039 | * |
| 5040 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5041 | * @param filter The IntentFilter for which a default handler is added. |
| 5042 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5043 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5044 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5045 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 5046 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5047 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5048 | if (mService != null) { |
| 5049 | try { |
| 5050 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 5051 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5052 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5053 | } |
| 5054 | } |
| 5055 | } |
| 5056 | |
| 5057 | /** |
| 5058 | * 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] | 5059 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5060 | * <p> |
| 5061 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5062 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5063 | * |
| 5064 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5065 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5066 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5067 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5068 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5069 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5070 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5071 | if (mService != null) { |
| 5072 | try { |
| 5073 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 5074 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5075 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5076 | } |
| 5077 | } |
| 5078 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5079 | |
| 5080 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5081 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 5082 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 5083 | * {@link #getApplicationRestrictions}. |
| 5084 | * <p> |
| 5085 | * This permission is persistent until it is later cleared by calling this method with a |
| 5086 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 5087 | * <p> |
| 5088 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5089 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5090 | * |
| 5091 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5092 | * @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] | 5093 | * APIs. If {@code null} is given the current package will be cleared. |
| 5094 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5095 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5096 | * |
| 5097 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 5098 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5099 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5100 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5101 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5102 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5103 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5104 | if (mService != null) { |
| 5105 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5106 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 5107 | throw new NameNotFoundException(packageName); |
| 5108 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5109 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5110 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5111 | } |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | /** |
| 5116 | * 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] | 5117 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 5118 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5119 | * |
| 5120 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5121 | * @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] | 5122 | * {@code null} if none is set. |
| 5123 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5124 | * |
| 5125 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 5126 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5127 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5128 | @Deprecated |
| 5129 | @Nullable |
| 5130 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5131 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5132 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5133 | if (mService != null) { |
| 5134 | try { |
| 5135 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 5136 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5137 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5138 | } |
| 5139 | } |
| 5140 | return null; |
| 5141 | } |
| 5142 | |
| 5143 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 5144 | * Called by any application to find out whether it has been granted permission via |
| 5145 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 5146 | * for the calling user. |
| 5147 | * |
| 5148 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 5149 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5150 | * |
| 5151 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 5152 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5153 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5154 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5155 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5156 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5157 | if (mService != null) { |
| 5158 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5159 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 5160 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5161 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5162 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5163 | } |
| 5164 | } |
| 5165 | return false; |
| 5166 | } |
| 5167 | |
| 5168 | /** |
| 5169 | * 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] | 5170 | * <p> |
| 5171 | * 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] | 5172 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5173 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5174 | * <p> |
| 5175 | * 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] | 5176 | * <ul> |
| 5177 | * <li>{@code boolean} |
| 5178 | * <li>{@code int} |
| 5179 | * <li>{@code String} or {@code String[]} |
| 5180 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5181 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5182 | * <p> |
| 5183 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5184 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5185 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5186 | * <p> |
| 5187 | * The application restrictions are only made visible to the target application via |
| 5188 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5189 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5190 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5191 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5192 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5193 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5194 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5195 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5196 | * @param packageName The name of the package to update restricted settings for. |
| 5197 | * @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] | 5198 | * set of active restrictions. |
| 5199 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5200 | * @see #setDelegatedScopes |
| 5201 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5202 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5203 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5204 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5205 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5206 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5207 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5208 | if (mService != null) { |
| 5209 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5210 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5211 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5212 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5213 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5214 | } |
| 5215 | } |
| 5216 | } |
| 5217 | |
| 5218 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5219 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 5220 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5221 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5222 | * {@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] | 5223 | * <p> |
| 5224 | * The calling device admin must have requested |
| 5225 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5226 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5227 | * <p> |
| 5228 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5229 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5230 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5231 | * |
| 5232 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5233 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5234 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5235 | * strictly disabled according to the state of the |
| 5236 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5237 | * <p> |
| 5238 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5239 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5240 | * device admins. |
| 5241 | * <p> |
| 5242 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5243 | * parameters. |
| 5244 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5245 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5246 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5247 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5248 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5249 | if (mService != null) { |
| 5250 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5251 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5252 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5253 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5254 | } |
| 5255 | } |
| 5256 | } |
| 5257 | |
| 5258 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5259 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5260 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5261 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5262 | * <p> |
| 5263 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5264 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5265 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5266 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5267 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5268 | * this function returns a list of configurations for all admins that declare |
| 5269 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5270 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5271 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5272 | * 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] | 5273 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5274 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5275 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5276 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5277 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5278 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5282 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5283 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5284 | if (mService != null) { |
| 5285 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5286 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5287 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5288 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5289 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5290 | } |
| 5291 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5292 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5296 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5297 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5298 | * <p> |
| 5299 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5300 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5301 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5302 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5303 | * @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] | 5304 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5305 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5306 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5307 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5308 | if (mService != null) { |
| 5309 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5310 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5311 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5312 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5313 | } |
| 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5318 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5319 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5320 | * <p> |
| 5321 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5322 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5323 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5324 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5325 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5326 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5327 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5328 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5329 | if (mService != null) { |
| 5330 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5331 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5332 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5333 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5334 | } |
| 5335 | } |
| 5336 | return false; |
| 5337 | } |
| 5338 | |
| 5339 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5340 | * Determine whether or not caller-Id information has been disabled. |
| 5341 | * |
| 5342 | * @param userHandle The user for whom to check the caller-id permission |
| 5343 | * @hide |
| 5344 | */ |
| 5345 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5346 | if (mService != null) { |
| 5347 | try { |
| 5348 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5349 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5350 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5351 | } |
| 5352 | } |
| 5353 | return false; |
| 5354 | } |
| 5355 | |
| 5356 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5357 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5358 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5359 | * <p> |
| 5360 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5361 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5362 | * |
| 5363 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5364 | * @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] | 5365 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5366 | */ |
| 5367 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5368 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5369 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5370 | if (mService != null) { |
| 5371 | try { |
| 5372 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5373 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5374 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5375 | } |
| 5376 | } |
| 5377 | } |
| 5378 | |
| 5379 | /** |
| 5380 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5381 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5382 | * <p> |
| 5383 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5384 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5385 | * |
| 5386 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5387 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5388 | */ |
| 5389 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5390 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5391 | if (mService != null) { |
| 5392 | try { |
| 5393 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 5394 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5395 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5396 | } |
| 5397 | } |
| 5398 | return false; |
| 5399 | } |
| 5400 | |
| 5401 | |
| 5402 | /** |
| 5403 | * Determine whether or not contacts search has been disabled. |
| 5404 | * |
| 5405 | * @param userHandle The user for whom to check the contacts search permission |
| 5406 | * @hide |
| 5407 | */ |
| 5408 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5409 | if (mService != null) { |
| 5410 | try { |
| 5411 | return mService |
| 5412 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5413 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5414 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5415 | } |
| 5416 | } |
| 5417 | return false; |
| 5418 | } |
| 5419 | |
| 5420 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5421 | * 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] | 5422 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5423 | * @hide |
| 5424 | */ |
| 5425 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5426 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5427 | if (mService != null) { |
| 5428 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5429 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5430 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5431 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5432 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5433 | } |
| 5434 | } |
| 5435 | } |
| 5436 | |
| 5437 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5438 | * 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] | 5439 | * @hide |
| 5440 | */ |
| 5441 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5442 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5443 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5444 | originalIntent); |
| 5445 | } |
| 5446 | |
| 5447 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5448 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5449 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5450 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5451 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5452 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5453 | * <p> |
| 5454 | * This API works on managed profile only. |
| 5455 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5456 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5457 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5458 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5459 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5460 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5461 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5462 | if (mService != null) { |
| 5463 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5464 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5465 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5466 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5467 | } |
| 5468 | } |
| 5469 | } |
| 5470 | |
| 5471 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5472 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5473 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5474 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5475 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5476 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5477 | * <p> |
| 5478 | * This API works on managed profile only. |
| 5479 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5480 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5481 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5482 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5483 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5484 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5485 | if (mService != null) { |
| 5486 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5487 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5488 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5489 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5490 | } |
| 5491 | } |
| 5492 | return true; |
| 5493 | } |
| 5494 | |
| 5495 | /** |
| 5496 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5497 | * <p> |
| 5498 | * This API works on managed profile UserHandle only. |
| 5499 | * |
| 5500 | * @param userHandle The user for whom to check the caller-id permission |
| 5501 | * @hide |
| 5502 | */ |
| 5503 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5504 | if (mService != null) { |
| 5505 | try { |
| 5506 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5507 | .getIdentifier()); |
| 5508 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5509 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5510 | } |
| 5511 | } |
| 5512 | return true; |
| 5513 | } |
| 5514 | |
| 5515 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5516 | * 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] | 5517 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5518 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5519 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5520 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5521 | * @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] | 5522 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5523 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5524 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5525 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5526 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5527 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5528 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5529 | if (mService != null) { |
| 5530 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5531 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5532 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5533 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5534 | } |
| 5535 | } |
| 5536 | } |
| 5537 | |
| 5538 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5539 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5540 | * 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] | 5541 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5542 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5543 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5544 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5545 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5546 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5547 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5548 | if (mService != null) { |
| 5549 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5550 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5551 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5552 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5553 | } |
| 5554 | } |
| 5555 | } |
| 5556 | |
| 5557 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5558 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5559 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5560 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5561 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5562 | * the list and not part of the system can not be enabled by the user. |
| 5563 | * <p> |
| 5564 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5565 | * used, calling with an empty list only allows the builtin system's services. |
| 5566 | * <p> |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5567 | * 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] | 5568 | * |
| 5569 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5570 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5571 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5572 | * accessibility services enabled, that are not in the list. |
| 5573 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5574 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5575 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5576 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5577 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5578 | if (mService != null) { |
| 5579 | try { |
| 5580 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5581 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5582 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5583 | } |
| 5584 | } |
| 5585 | return false; |
| 5586 | } |
| 5587 | |
| 5588 | /** |
| 5589 | * 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] | 5590 | * <p> |
| 5591 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5592 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5593 | * |
| 5594 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5595 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5596 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5597 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5598 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5599 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5600 | if (mService != null) { |
| 5601 | try { |
| 5602 | return mService.getPermittedAccessibilityServices(admin); |
| 5603 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5604 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5605 | } |
| 5606 | } |
| 5607 | return null; |
| 5608 | } |
| 5609 | |
| 5610 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5611 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5612 | * |
| 5613 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5614 | * @param packageName Accessibility service package name that needs to be checked. |
| 5615 | * @param userHandle user id the admin is running as. |
| 5616 | * @return true if the accessibility service is permitted, otherwise false. |
| 5617 | * |
| 5618 | * @hide |
| 5619 | */ |
| 5620 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5621 | @NonNull String packageName, int userHandle) { |
| 5622 | if (mService != null) { |
| 5623 | try { |
| 5624 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5625 | userHandle); |
| 5626 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5627 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5628 | } |
| 5629 | } |
| 5630 | return false; |
| 5631 | } |
| 5632 | |
| 5633 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5634 | * Returns the list of accessibility services permitted by the device or profiles |
| 5635 | * owners of this user. |
| 5636 | * |
| 5637 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5638 | * it will contain the intersection of the permitted lists for any device or profile |
| 5639 | * owners that apply to this user. It will also include any system accessibility services. |
| 5640 | * |
| 5641 | * @param userId which user to check for. |
| 5642 | * @return List of accessiblity service package names. |
| 5643 | * @hide |
| 5644 | */ |
| 5645 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5646 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5647 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5648 | if (mService != null) { |
| 5649 | try { |
| 5650 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5651 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5652 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5653 | } |
| 5654 | } |
| 5655 | return null; |
| 5656 | } |
| 5657 | |
| 5658 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5659 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5660 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5661 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5662 | * When zero or more packages have been added, input method that are not in the list and not |
| 5663 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5664 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5665 | * <p> |
| 5666 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5667 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5668 | * <p> |
| 5669 | * 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] | 5670 | * |
| 5671 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5672 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5673 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5674 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5675 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5676 | */ |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5677 | public boolean setPermittedInputMethods( |
| 5678 | @NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5679 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5680 | if (mService != null) { |
| 5681 | try { |
| 5682 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5683 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5684 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5685 | } |
| 5686 | } |
| 5687 | return false; |
| 5688 | } |
| 5689 | |
| 5690 | |
| 5691 | /** |
| 5692 | * 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] | 5693 | * <p> |
| 5694 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5695 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5696 | * |
| 5697 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5698 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5699 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5700 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5701 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5702 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5703 | if (mService != null) { |
| 5704 | try { |
| 5705 | return mService.getPermittedInputMethods(admin); |
| 5706 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5707 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5708 | } |
| 5709 | } |
| 5710 | return null; |
| 5711 | } |
| 5712 | |
| 5713 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5714 | * Called by the system to check if a specific input method is disabled by admin. |
| 5715 | * |
| 5716 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5717 | * @param packageName Input method package name that needs to be checked. |
| 5718 | * @param userHandle user id the admin is running as. |
| 5719 | * @return true if the input method is permitted, otherwise false. |
| 5720 | * |
| 5721 | * @hide |
| 5722 | */ |
| 5723 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5724 | @NonNull String packageName, int userHandle) { |
| 5725 | if (mService != null) { |
| 5726 | try { |
| 5727 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5728 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5729 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5730 | } |
| 5731 | } |
| 5732 | return false; |
| 5733 | } |
| 5734 | |
| 5735 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5736 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5737 | * 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] | 5738 | * |
| 5739 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5740 | * it will contain the intersection of the permitted lists for any device or profile |
| 5741 | * owners that apply to this user. It will also include any system input methods. |
| 5742 | * |
| 5743 | * @return List of input method package names. |
| 5744 | * @hide |
| 5745 | */ |
| 5746 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5747 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5748 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5749 | if (mService != null) { |
| 5750 | try { |
| 5751 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5752 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5753 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5754 | } |
| 5755 | } |
| 5756 | return null; |
| 5757 | } |
| 5758 | |
| 5759 | /** |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5760 | * Called by a profile owner of a managed profile to set the packages that are allowed to use |
| 5761 | * a {@link android.service.notification.NotificationListenerService} in the primary user to |
| 5762 | * see notifications from the managed profile. By default all packages are permitted by this |
| 5763 | * policy. When zero or more packages have been added, notification listeners installed on the |
| 5764 | * primary user that are not in the list and are not part of the system won't receive events |
| 5765 | * for managed profile notifications. |
| 5766 | * <p> |
| 5767 | * Calling with a {@code null} value for the list disables the restriction so that all |
| 5768 | * notification listener services be used. Calling with an empty list disables all but the |
| 5769 | * system's own notification listeners. System notification listener services are always |
| 5770 | * available to the user. |
| 5771 | * <p> |
| 5772 | * If a device or profile owner want to stop notification listeners in their user from seeing |
| 5773 | * that user's notifications they should prevent that service from running instead (e.g. via |
| 5774 | * {@link #setApplicationHidden(ComponentName, String, boolean)}) |
| 5775 | * |
| 5776 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5777 | * @param packageList List of package names to whitelist |
| 5778 | * @return true if setting the restriction succeeded. It will fail if called outside a managed |
| 5779 | * profile |
| 5780 | * @throws SecurityException if {@code admin} is not a profile owner. |
| 5781 | * |
| 5782 | * @see android.service.notification.NotificationListenerService |
| 5783 | */ |
| 5784 | public boolean setPermittedCrossProfileNotificationListeners( |
| 5785 | @NonNull ComponentName admin, @Nullable List<String> packageList) { |
| 5786 | throwIfParentInstance("setPermittedCrossProfileNotificationListeners"); |
| 5787 | if (mService != null) { |
| 5788 | try { |
| 5789 | return mService.setPermittedCrossProfileNotificationListeners(admin, packageList); |
| 5790 | } catch (RemoteException e) { |
| 5791 | throw e.rethrowFromSystemServer(); |
| 5792 | } |
| 5793 | } |
| 5794 | return false; |
| 5795 | } |
| 5796 | |
| 5797 | /** |
| 5798 | * Returns the list of packages installed on the primary user that allowed to use a |
| 5799 | * {@link android.service.notification.NotificationListenerService} to receive |
| 5800 | * notifications from this managed profile, as set by the profile owner. |
| 5801 | * <p> |
| 5802 | * An empty list means no notification listener services except system ones are allowed. |
| 5803 | * A {@code null} return value indicates that all notification listeners are allowed. |
| 5804 | */ |
| 5805 | public @Nullable List<String> getPermittedCrossProfileNotificationListeners( |
| 5806 | @NonNull ComponentName admin) { |
| 5807 | throwIfParentInstance("getPermittedCrossProfileNotificationListeners"); |
| 5808 | if (mService != null) { |
| 5809 | try { |
| 5810 | return mService.getPermittedCrossProfileNotificationListeners(admin); |
| 5811 | } catch (RemoteException e) { |
| 5812 | throw e.rethrowFromSystemServer(); |
| 5813 | } |
| 5814 | } |
| 5815 | return null; |
| 5816 | } |
| 5817 | |
| 5818 | /** |
| 5819 | * Returns true if {@code NotificationListenerServices} from the given package are allowed to |
| 5820 | * receive events for notifications from the given user id. Can only be called by the system uid |
| 5821 | * |
| 5822 | * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List) |
| 5823 | * |
| 5824 | * @hide |
| 5825 | */ |
| 5826 | public boolean isNotificationListenerServicePermitted( |
| 5827 | @NonNull String packageName, @UserIdInt int userId) { |
| 5828 | if (mService != null) { |
| 5829 | try { |
| 5830 | return mService.isNotificationListenerServicePermitted(packageName, userId); |
| 5831 | } catch (RemoteException e) { |
| 5832 | throw e.rethrowFromSystemServer(); |
| 5833 | } |
| 5834 | } |
| 5835 | return true; |
| 5836 | } |
| 5837 | |
| 5838 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5839 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 5840 | * function can be called by a device owner or by a delegate given the |
| 5841 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 5842 | * <p> |
| 5843 | * 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] | 5844 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5845 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5846 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5847 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5848 | * @see #setDelegatedScopes |
| 5849 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5850 | * @hide |
| 5851 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5852 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5853 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5854 | if (mService != null) { |
| 5855 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5856 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5857 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5858 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5859 | } |
| 5860 | } |
| 5861 | return null; |
| 5862 | } |
| 5863 | |
| 5864 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5865 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 5866 | * function can be called by a device owner or by a delegate given the |
| 5867 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5868 | * |
| 5869 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5870 | * automatically pre-cached.</p> |
| 5871 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5872 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5873 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5874 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5875 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5876 | * @see #setDelegatedScopes |
| 5877 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5878 | * @hide |
| 5879 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5880 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5881 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5882 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5883 | if (mService != null) { |
| 5884 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5885 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5886 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5887 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5888 | } |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5893 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5894 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5895 | * created. If you need to persist an identifier for this user, use |
| 5896 | * {@link UserManager#getSerialNumberForUser}. |
| 5897 | * |
| 5898 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5899 | * @param name the user's name |
| 5900 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5901 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5902 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5903 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5904 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5905 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5906 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5907 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5908 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5909 | return null; |
| 5910 | } |
| 5911 | |
| 5912 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5913 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5914 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5915 | * created. If you need to persist an identifier for this user, use |
| 5916 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5917 | * immediately. |
| 5918 | * |
| 5919 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5920 | * as registered as an active admin on the new user. The profile owner package will be |
| 5921 | * installed on the new user if it already is installed on the device. |
| 5922 | * |
| 5923 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5924 | * profileOwnerComponent when onEnable is called. |
| 5925 | * |
| 5926 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5927 | * @param name the user's name |
| 5928 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5929 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5930 | * the user. |
| 5931 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5932 | * on the new user. |
| 5933 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5934 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5935 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5936 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5937 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5938 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5939 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5940 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5941 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5942 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5943 | return null; |
| 5944 | } |
| 5945 | |
| 5946 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5947 | * 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] | 5948 | */ |
| 5949 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5950 | |
| 5951 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5952 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5953 | * ephemeral. |
| 5954 | * @hide |
| 5955 | */ |
| 5956 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5957 | |
| 5958 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5959 | * Called by a device owner to create a user with the specified name and a given component of |
| 5960 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5961 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5962 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5963 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5964 | * <p> |
| 5965 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5966 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5967 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5968 | * on the new user. |
| 5969 | * <p> |
| 5970 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5971 | * 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] | 5972 | * |
| 5973 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5974 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5975 | * @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] | 5976 | * same package as admin, otherwise no user is created and an |
| 5977 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5978 | * @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] | 5979 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5980 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5981 | * @see UserHandle |
| 5982 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5983 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5984 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5985 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5986 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5987 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5988 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5989 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5990 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5991 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5992 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5993 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5994 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5995 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5996 | } |
| 5997 | |
| 5998 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5999 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 6000 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6001 | * |
| 6002 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6003 | * @param userHandle the user to remove. |
| 6004 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6005 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6006 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6007 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6008 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6009 | try { |
| 6010 | return mService.removeUser(admin, userHandle); |
| 6011 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6012 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6013 | } |
| 6014 | } |
| 6015 | |
| 6016 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6017 | * Called by a device owner to switch the specified user to the foreground. |
| 6018 | * |
| 6019 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6020 | * @param userHandle the user to switch to; null will switch to primary. |
| 6021 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6022 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6023 | * @see Intent#ACTION_USER_FOREGROUND |
| 6024 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6025 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6026 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6027 | try { |
| 6028 | return mService.switchUser(admin, userHandle); |
| 6029 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6030 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6031 | } |
| 6032 | } |
| 6033 | |
| 6034 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6035 | * Retrieves the application restrictions for a given target application running in the calling |
| 6036 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6037 | * <p> |
| 6038 | * 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] | 6039 | * application restrictions via {@link #setDelegatedScopes} with the |
| 6040 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6041 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6042 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 6043 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6044 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6045 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6046 | * @param packageName The name of the package to fetch restricted settings of. |
| 6047 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6048 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 6049 | * {@link Bundle} if no restrictions have been set. |
| 6050 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6051 | * @see #setDelegatedScopes |
| 6052 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6053 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6054 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6055 | public @NonNull Bundle getApplicationRestrictions( |
| 6056 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6057 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6058 | if (mService != null) { |
| 6059 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6060 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 6061 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6062 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6063 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6064 | } |
| 6065 | } |
| 6066 | return null; |
| 6067 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6068 | |
| 6069 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6070 | * 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] | 6071 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6072 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6073 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6074 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6075 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6076 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6077 | * for the list of keys. |
| 6078 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6079 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6080 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6081 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6082 | if (mService != null) { |
| 6083 | try { |
| 6084 | mService.setUserRestriction(admin, key, true); |
| 6085 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6086 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6087 | } |
| 6088 | } |
| 6089 | } |
| 6090 | |
| 6091 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6092 | * 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] | 6093 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6094 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6095 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6096 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6097 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6098 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6099 | * for the list of keys. |
| 6100 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6101 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6102 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6103 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6104 | if (mService != null) { |
| 6105 | try { |
| 6106 | mService.setUserRestriction(admin, key, false); |
| 6107 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6108 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6109 | } |
| 6110 | } |
| 6111 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 6112 | |
| 6113 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6114 | * Called by a profile or device owner to get user restrictions set with |
| 6115 | * {@link #addUserRestriction(ComponentName, String)}. |
| 6116 | * <p> |
| 6117 | * 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] | 6118 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6119 | * {@link UserManager#getUserRestrictions()}. |
| 6120 | * |
| 6121 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6122 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6123 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6124 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6125 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6126 | Bundle ret = null; |
| 6127 | if (mService != null) { |
| 6128 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 6129 | ret = mService.getUserRestrictions(admin); |
| 6130 | } catch (RemoteException e) { |
| 6131 | throw e.rethrowFromSystemServer(); |
| 6132 | } |
| 6133 | } |
| 6134 | return ret == null ? new Bundle() : ret; |
| 6135 | } |
| 6136 | |
| 6137 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6138 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 6139 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 6140 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 6141 | * was disabled by an admin, and include a link for more information. The default content of |
| 6142 | * the dialog can be changed by the restricting admin via |
| 6143 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 6144 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 6145 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 6146 | * user restriction from {@link UserManager}, e.g. |
| 6147 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
| 6148 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 6149 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 6150 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 6151 | */ |
| 6152 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 6153 | throwIfParentInstance("createAdminSupportIntent"); |
| 6154 | if (mService != null) { |
| 6155 | try { |
| 6156 | return mService.createAdminSupportIntent(restriction); |
| 6157 | } catch (RemoteException e) { |
| 6158 | throw e.rethrowFromSystemServer(); |
| 6159 | } |
| 6160 | } |
| 6161 | return null; |
| 6162 | } |
| 6163 | |
| 6164 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6165 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 6166 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 6167 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6168 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6169 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6170 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6171 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6172 | * @param packageName The name of the package to hide or unhide. |
| 6173 | * @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] | 6174 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6175 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6176 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6177 | * @see #setDelegatedScopes |
| 6178 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6179 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6180 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6181 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6182 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6183 | if (mService != null) { |
| 6184 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6185 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 6186 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6187 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6188 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6189 | } |
| 6190 | } |
| 6191 | return false; |
| 6192 | } |
| 6193 | |
| 6194 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6195 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 6196 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6197 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6198 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6199 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6200 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6201 | * @param packageName The name of the package to retrieve the hidden status of. |
| 6202 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6203 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6204 | * @see #setDelegatedScopes |
| 6205 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6206 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6207 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6208 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6209 | if (mService != null) { |
| 6210 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6211 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6212 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6213 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6214 | } |
| 6215 | } |
| 6216 | return false; |
| 6217 | } |
| 6218 | |
| 6219 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6220 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 6221 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6222 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6223 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6224 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6225 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6226 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6227 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6228 | * @see #setDelegatedScopes |
| 6229 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6230 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6231 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6232 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6233 | if (mService != null) { |
| 6234 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6235 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6236 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6237 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6238 | } |
| 6239 | } |
| 6240 | } |
| 6241 | |
| 6242 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6243 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 6244 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 6245 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6246 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6247 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6248 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6249 | * @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] | 6250 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6251 | * @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] | 6252 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6253 | * @see #setDelegatedScopes |
| 6254 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6255 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6256 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6257 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6258 | if (mService != null) { |
| 6259 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6260 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6261 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6262 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6263 | } |
| 6264 | } |
| 6265 | return 0; |
| 6266 | } |
| 6267 | |
| 6268 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 6269 | * Called by a device owner or profile owner to disable account management for a specific type |
| 6270 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6271 | * <p> |
| 6272 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 6273 | * exception will be thrown. |
| 6274 | * <p> |
| 6275 | * When account management is disabled for an account type, adding or removing an account of |
| 6276 | * that type will not be possible. |
| 6277 | * <p> |
| 6278 | * 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] | 6279 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 6280 | * management for a specific type is disabled. |
| 6281 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6282 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6283 | * @param accountType For which account management is disabled or enabled. |
| 6284 | * @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] | 6285 | * enabled (false). |
| 6286 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6287 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6288 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6289 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6290 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6291 | if (mService != null) { |
| 6292 | try { |
| 6293 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 6294 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6295 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6296 | } |
| 6297 | } |
| 6298 | } |
| 6299 | |
| 6300 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6301 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 6302 | * |
| 6303 | * <p> Account management can be disabled/enabled by calling |
| 6304 | * {@link #setAccountManagementDisabled}. |
| 6305 | * |
| 6306 | * @return a list of account types for which account management has been disabled. |
| 6307 | * |
| 6308 | * @see #setAccountManagementDisabled |
| 6309 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6310 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6311 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 6312 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6313 | } |
| 6314 | |
| 6315 | /** |
| 6316 | * @see #getAccountTypesWithManagementDisabled() |
| 6317 | * @hide |
| 6318 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6319 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6320 | if (mService != null) { |
| 6321 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6322 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6323 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6324 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6325 | } |
| 6326 | } |
| 6327 | |
| 6328 | return null; |
| 6329 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6330 | |
| 6331 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6332 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6333 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6334 | * 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] | 6335 | * 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] | 6336 | * package list results in locked tasks belonging to those packages to be finished. |
| 6337 | * <p> |
| 6338 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6339 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages |
| 6340 | * set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6341 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6342 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6343 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6344 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6345 | * an affiliated user or profile. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6346 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6347 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6348 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6349 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6350 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6351 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6352 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6353 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6354 | if (mService != null) { |
| 6355 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6356 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6357 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6358 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6359 | } |
| 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6364 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6365 | * |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6366 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6367 | * an affiliated user or profile. |
| 6368 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6369 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6370 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6371 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6372 | if (mService != null) { |
| 6373 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6374 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6375 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6376 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6377 | } |
| 6378 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6379 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6380 | } |
| 6381 | |
| 6382 | /** |
| 6383 | * This function lets the caller know whether the given component is allowed to start the |
| 6384 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6385 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6386 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6387 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6388 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6389 | if (mService != null) { |
| 6390 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6391 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6392 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6393 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6394 | } |
| 6395 | } |
| 6396 | return false; |
| 6397 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6398 | |
| 6399 | /** |
| 6400 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 6401 | * of the setting is in the correct form for the setting type should be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6402 | * <p> |
| 6403 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6404 | * <ul> |
| 6405 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 6406 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 6407 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6408 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6409 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6410 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6411 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 6412 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 6413 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 6414 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 6415 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6416 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6417 | * <p> |
| 6418 | * 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] | 6419 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6420 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 6421 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6422 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6423 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6424 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 6425 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6426 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6427 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 6428 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6429 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6430 | * |
| 6431 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6432 | * @param setting The name of the setting to update. |
| 6433 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6434 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6435 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6436 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6437 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6438 | if (mService != null) { |
| 6439 | try { |
| 6440 | mService.setGlobalSetting(admin, setting, value); |
| 6441 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6442 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6443 | } |
| 6444 | } |
| 6445 | } |
| 6446 | |
| 6447 | /** |
| 6448 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 6449 | * that the value of the setting is in the correct form for the setting type should be performed |
| 6450 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6451 | * <p> |
| 6452 | * 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] | 6453 | * <ul> |
| 6454 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
| 6455 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 6456 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6457 | * <p> |
| 6458 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6459 | * <ul> |
| 6460 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 6461 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6462 | * |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 6463 | * <strong>Note: Starting from Android O, apps should no longer call this method with the |
| 6464 | * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is |
| 6465 | * deprecated. Instead, device owners or profile owners should use the restriction |
| 6466 | * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
| 6467 | * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method |
| 6468 | * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, |
| 6469 | * an {@link UnsupportedOperationException} is thrown. |
| 6470 | * </strong> |
| 6471 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6472 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6473 | * @param setting The name of the setting to update. |
| 6474 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6475 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6476 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6477 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6478 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6479 | if (mService != null) { |
| 6480 | try { |
| 6481 | mService.setSecureSetting(admin, setting, value); |
| 6482 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6483 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6484 | } |
| 6485 | } |
| 6486 | } |
| 6487 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6488 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6489 | * Designates a specific service component as the provider for making permission requests of a |
| 6490 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6491 | * <p/> |
| 6492 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6493 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6494 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6495 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6496 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6497 | * provider previously assigned. |
| 6498 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6499 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6500 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6501 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6502 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6503 | if (mService != null) { |
| 6504 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6505 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6506 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6507 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6508 | } |
| 6509 | } |
| 6510 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6511 | |
| 6512 | /** |
| 6513 | * 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] | 6514 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6515 | * |
| 6516 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6517 | * @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] | 6518 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6519 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6520 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6521 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6522 | if (mService != null) { |
| 6523 | try { |
| 6524 | mService.setMasterVolumeMuted(admin, on); |
| 6525 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6526 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6527 | } |
| 6528 | } |
| 6529 | } |
| 6530 | |
| 6531 | /** |
| 6532 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6533 | * |
| 6534 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6535 | * @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] | 6536 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6537 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6538 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6539 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6540 | if (mService != null) { |
| 6541 | try { |
| 6542 | return mService.isMasterVolumeMuted(admin); |
| 6543 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6544 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6545 | } |
| 6546 | } |
| 6547 | return false; |
| 6548 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6549 | |
| 6550 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6551 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6552 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6553 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6554 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6555 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6556 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6557 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6558 | * @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] | 6559 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6560 | * @see #setDelegatedScopes |
| 6561 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6562 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6563 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6564 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6565 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6566 | if (mService != null) { |
| 6567 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6568 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6569 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6570 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6571 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6577 | * 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] | 6578 | * 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] | 6579 | * <p> |
| 6580 | * <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] | 6581 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6582 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6583 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6584 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6585 | * @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] | 6586 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6587 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6588 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6589 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6590 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6591 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6592 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6593 | if (mService != null) { |
| 6594 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6595 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6596 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6597 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6598 | } |
| 6599 | } |
| 6600 | return false; |
| 6601 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6602 | |
| 6603 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6604 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6605 | * package to be available in the parent profile. As a result the user will be able to add |
| 6606 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6607 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6608 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6609 | * <p> |
| 6610 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6611 | * |
| 6612 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6613 | * @param packageName The package from which widget providers are white-listed. |
| 6614 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6615 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6616 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6617 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6618 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6619 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6620 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6621 | if (mService != null) { |
| 6622 | try { |
| 6623 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6624 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6625 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6626 | } |
| 6627 | } |
| 6628 | return false; |
| 6629 | } |
| 6630 | |
| 6631 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6632 | * 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] | 6633 | * package to be available in the parent profile. For this method to take effect the package |
| 6634 | * should have been added via |
| 6635 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6636 | * <p> |
| 6637 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6638 | * |
| 6639 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6640 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6641 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6642 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6643 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6644 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6645 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6646 | public boolean removeCrossProfileWidgetProvider( |
| 6647 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6648 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6649 | if (mService != null) { |
| 6650 | try { |
| 6651 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6652 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6653 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6654 | } |
| 6655 | } |
| 6656 | return false; |
| 6657 | } |
| 6658 | |
| 6659 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6660 | * 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] | 6661 | * available in the parent profile. |
| 6662 | * |
| 6663 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6664 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6665 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6666 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6667 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6668 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6669 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6670 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6671 | if (mService != null) { |
| 6672 | try { |
| 6673 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6674 | if (providers != null) { |
| 6675 | return providers; |
| 6676 | } |
| 6677 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6678 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6679 | } |
| 6680 | } |
| 6681 | return Collections.emptyList(); |
| 6682 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6683 | |
| 6684 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6685 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6686 | * |
| 6687 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6688 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6689 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6690 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6691 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6692 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6693 | try { |
| 6694 | mService.setUserIcon(admin, icon); |
| 6695 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6696 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6697 | } |
| 6698 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6699 | |
| 6700 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6701 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6702 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6703 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6704 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6705 | * components in the device owner package can set system update policies and the most |
| 6706 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6707 | * @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] | 6708 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6709 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6710 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6711 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6712 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6713 | if (mService != null) { |
| 6714 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6715 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6716 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6717 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6718 | } |
| 6719 | } |
| 6720 | } |
| 6721 | |
| 6722 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6723 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6724 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6725 | * @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] | 6726 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6727 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6728 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6729 | if (mService != null) { |
| 6730 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6731 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6732 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6733 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6734 | } |
| 6735 | } |
| 6736 | return null; |
| 6737 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6738 | |
| 6739 | /** |
| 6740 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6741 | * <p> |
| 6742 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6743 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6744 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6745 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6746 | * |
| 6747 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6748 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6749 | * @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] | 6750 | * place. {@code true} otherwise. |
| 6751 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6752 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6753 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6754 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6755 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6756 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6757 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6758 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6759 | } |
| 6760 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6761 | |
| 6762 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6763 | * 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] | 6764 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6765 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6766 | * |
| 6767 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6768 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6769 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6770 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6771 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6772 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6773 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6774 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6775 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6776 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6777 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6778 | } |
| 6779 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6780 | |
| 6781 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6782 | * Called by the system update service to notify device and profile owners of pending system |
| 6783 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6784 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6785 | * 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] | 6786 | * update is a security patch. Otherwise, use |
| 6787 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 6788 | * |
| 6789 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6790 | * indicating when the current pending update was first available. {@code -1} if no |
| 6791 | * update is available. |
| 6792 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6793 | * @hide |
| 6794 | */ |
| 6795 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6796 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6797 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6798 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6799 | if (mService != null) { |
| 6800 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6801 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 6802 | } catch (RemoteException re) { |
| 6803 | throw re.rethrowFromSystemServer(); |
| 6804 | } |
| 6805 | } |
| 6806 | } |
| 6807 | |
| 6808 | /** |
| 6809 | * Called by the system update service to notify device and profile owners of pending system |
| 6810 | * updates. |
| 6811 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6812 | * This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6813 | * when it is known whether the pending system update is a security patch. |
| 6814 | * |
| 6815 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6816 | * indicating when the current pending update was first available. {@code -1} if no |
| 6817 | * update is available. |
| 6818 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 6819 | * {@code false} if not. |
| 6820 | * @see #notifyPendingSystemUpdate(long) |
| 6821 | * @hide |
| 6822 | */ |
| 6823 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6824 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6825 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 6826 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 6827 | if (mService != null) { |
| 6828 | try { |
| 6829 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 6830 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6831 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6832 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6833 | } |
| 6834 | } |
| 6835 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6836 | |
| 6837 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 6838 | * Called by device or profile owners to get information about a pending system update. |
| 6839 | * |
| 6840 | * @param admin Which profile or device owner this request is associated with. |
| 6841 | * @return Information about a pending system update or {@code null} if no update pending. |
| 6842 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 6843 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 6844 | */ |
| 6845 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 6846 | throwIfParentInstance("getPendingSystemUpdate"); |
| 6847 | try { |
| 6848 | return mService.getPendingSystemUpdate(admin); |
| 6849 | } catch (RemoteException re) { |
| 6850 | throw re.rethrowFromSystemServer(); |
| 6851 | } |
| 6852 | } |
| 6853 | |
| 6854 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6855 | * Set the default response for future runtime permission requests by applications. This |
| 6856 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6857 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 6858 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 6859 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 6860 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 6861 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 6862 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6863 | * <p/> |
| 6864 | * 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] | 6865 | * 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] | 6866 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6867 | * @param admin Which profile or device owner this request is associated with. |
| 6868 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6869 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6870 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6871 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6872 | * @see #setDelegatedScopes |
| 6873 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6874 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6875 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6876 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6877 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6878 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6879 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6880 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | /** |
| 6885 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6886 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6887 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6888 | * @param admin Which profile or device owner this request is associated with. |
| 6889 | * @return the current policy for future permission requests. |
| 6890 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6891 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6892 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6893 | try { |
| 6894 | return mService.getPermissionPolicy(admin); |
| 6895 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6896 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6897 | } |
| 6898 | } |
| 6899 | |
| 6900 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6901 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6902 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6903 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6904 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6905 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6906 | * 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] | 6907 | * by a profile owner, device owner, or a delegate given the |
| 6908 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6909 | * <p/> |
| 6910 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6911 | * the permission. It retains the previous grant, if any. |
| 6912 | * <p/> |
| 6913 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6914 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6915 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6916 | * @param admin Which profile or device owner this request is associated with. |
| 6917 | * @param packageName The application to grant or revoke a permission to. |
| 6918 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6919 | * @param grantState The permission grant state which is one of |
| 6920 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6921 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6922 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6923 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6924 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6925 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6926 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6927 | * @see #setDelegatedScopes |
| 6928 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6929 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6930 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6931 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6932 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6933 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6934 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6935 | permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6936 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6937 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6938 | } |
| 6939 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6940 | |
| 6941 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6942 | * Returns the current grant state of a runtime permission for a specific application. This |
| 6943 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6944 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6945 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6946 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 6947 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6948 | * @param packageName The application to check the grant state for. |
| 6949 | * @param permission The permission to check for. |
| 6950 | * @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] | 6951 | * has not set a grant state, the return value is |
| 6952 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6953 | * permission is currently granted for the package. |
| 6954 | * <p/> |
| 6955 | * If a grant state was set by the profile or device owner, then the return value will |
| 6956 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6957 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6958 | * currently denied or granted. |
| 6959 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6960 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6961 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6962 | * @see #setDelegatedScopes |
| 6963 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6964 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 6965 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6966 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6967 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6968 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6969 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6970 | permission); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6971 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6972 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6973 | } |
| 6974 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6975 | |
| 6976 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6977 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 6978 | * or device, setting itself as the device or profile owner. |
| 6979 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6980 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6981 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6982 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6983 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 6984 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6985 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6986 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6987 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6988 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6989 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6990 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6991 | } |
| 6992 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6993 | |
| 6994 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6995 | * Checks whether it is possible to initiate provisioning a managed device, |
| 6996 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6997 | * |
| 6998 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6999 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 7000 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 7001 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7002 | * @param packageName The package of the component that would be set as device, user, or profile |
| 7003 | * owner. |
| 7004 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7005 | * @hide |
| 7006 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7007 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 7008 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7009 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7010 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7011 | } catch (RemoteException re) { |
| 7012 | throw re.rethrowFromSystemServer(); |
| 7013 | } |
| 7014 | } |
| 7015 | |
| 7016 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7017 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 7018 | * 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] | 7019 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7020 | * @param admin Which profile owner this request is associated with. |
| 7021 | * @return if this user is a managed profile of another user. |
| 7022 | */ |
| 7023 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7024 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7025 | try { |
| 7026 | return mService.isManagedProfile(admin); |
| 7027 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7028 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7029 | } |
| 7030 | } |
| 7031 | |
| 7032 | /** |
| 7033 | * @hide |
| 7034 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 7035 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 7036 | * @param admin Which device owner this request is associated with. |
| 7037 | * @return if this user is a system-only user. |
| 7038 | */ |
| 7039 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 7040 | try { |
| 7041 | return mService.isSystemOnlyUser(admin); |
| 7042 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7043 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7044 | } |
| 7045 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7046 | |
| 7047 | /** |
| 7048 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 7049 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7050 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7051 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 7052 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 7053 | * <p> |
| 7054 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 7055 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7056 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7057 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7058 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7059 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7060 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7061 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7062 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7063 | } |
| 7064 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7065 | |
| 7066 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7067 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 7068 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7069 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7070 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7071 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7072 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7073 | */ |
| 7074 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7075 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7076 | try { |
| 7077 | mService.reboot(admin); |
| 7078 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7079 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7080 | } |
| 7081 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7082 | |
| 7083 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7084 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 7085 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 7086 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 7087 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 7088 | * truncated. |
| 7089 | * <p> |
| 7090 | * 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] | 7091 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7092 | * and set a new version of this string accordingly. |
| 7093 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7094 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7095 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7096 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 7097 | * existing message. |
| 7098 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7099 | */ |
| 7100 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7101 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7102 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7103 | if (mService != null) { |
| 7104 | try { |
| 7105 | mService.setShortSupportMessage(admin, message); |
| 7106 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7107 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7108 | } |
| 7109 | } |
| 7110 | } |
| 7111 | |
| 7112 | /** |
| 7113 | * Called by a device admin to get the short support message. |
| 7114 | * |
| 7115 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7116 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 7117 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7118 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7119 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7120 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7121 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7122 | if (mService != null) { |
| 7123 | try { |
| 7124 | return mService.getShortSupportMessage(admin); |
| 7125 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7126 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7127 | } |
| 7128 | } |
| 7129 | return null; |
| 7130 | } |
| 7131 | |
| 7132 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7133 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 7134 | * in the device administators settings screen. |
| 7135 | * <p> |
| 7136 | * 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] | 7137 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7138 | * and set a new version of this string accordingly. |
| 7139 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7140 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7141 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7142 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 7143 | * existing message. |
| 7144 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7145 | */ |
| 7146 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7147 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7148 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7149 | if (mService != null) { |
| 7150 | try { |
| 7151 | mService.setLongSupportMessage(admin, message); |
| 7152 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7153 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7154 | } |
| 7155 | } |
| 7156 | } |
| 7157 | |
| 7158 | /** |
| 7159 | * Called by a device admin to get the long support message. |
| 7160 | * |
| 7161 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7162 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 7163 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7164 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7165 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7166 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7167 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7168 | if (mService != null) { |
| 7169 | try { |
| 7170 | return mService.getLongSupportMessage(admin); |
| 7171 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7172 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7173 | } |
| 7174 | } |
| 7175 | return null; |
| 7176 | } |
| 7177 | |
| 7178 | /** |
| 7179 | * Called by the system to get the short support message. |
| 7180 | * |
| 7181 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7182 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7183 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7184 | * |
| 7185 | * @hide |
| 7186 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7187 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7188 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7189 | if (mService != null) { |
| 7190 | try { |
| 7191 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 7192 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7193 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7194 | } |
| 7195 | } |
| 7196 | return null; |
| 7197 | } |
| 7198 | |
| 7199 | |
| 7200 | /** |
| 7201 | * Called by the system to get the long support message. |
| 7202 | * |
| 7203 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7204 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7205 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7206 | * |
| 7207 | * @hide |
| 7208 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7209 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 7210 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7211 | if (mService != null) { |
| 7212 | try { |
| 7213 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 7214 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7215 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7216 | } |
| 7217 | } |
| 7218 | return null; |
| 7219 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7220 | |
| 7221 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 7222 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 7223 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7224 | * |
| 7225 | * <p>The following methods are supported for the parent instance, all other methods will |
| 7226 | * throw a SecurityException when called on the parent instance: |
| 7227 | * <ul> |
| 7228 | * <li>{@link #getPasswordQuality}</li> |
| 7229 | * <li>{@link #setPasswordQuality}</li> |
| 7230 | * <li>{@link #getPasswordMinimumLength}</li> |
| 7231 | * <li>{@link #setPasswordMinimumLength}</li> |
| 7232 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 7233 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 7234 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 7235 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 7236 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 7237 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 7238 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 7239 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 7240 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 7241 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 7242 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 7243 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 7244 | * <li>{@link #getPasswordHistoryLength}</li> |
| 7245 | * <li>{@link #setPasswordHistoryLength}</li> |
| 7246 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 7247 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 7248 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 7249 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7250 | * <li>{@link #isActivePasswordSufficient}</li> |
| 7251 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 7252 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 7253 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 7254 | * <li>{@link #getMaximumTimeToLock}</li> |
| 7255 | * <li>{@link #setMaximumTimeToLock}</li> |
| 7256 | * <li>{@link #lockNow}</li> |
| 7257 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 7258 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 7259 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 7260 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 7261 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 7262 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7263 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7264 | * |
| 7265 | * @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] | 7266 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7267 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7268 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7269 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7270 | try { |
| 7271 | if (!mService.isManagedProfile(admin)) { |
| 7272 | throw new SecurityException("The current user does not have a parent profile."); |
| 7273 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7274 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7275 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7276 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7277 | } |
| 7278 | } |
| 7279 | |
| 7280 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7281 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7282 | * |
| 7283 | * <p> Security logs contain various information intended for security auditing purposes. |
| 7284 | * See {@link SecurityEvent} for details. |
| 7285 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7286 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 7287 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7288 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7289 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7290 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7291 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7292 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7293 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7294 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7295 | * @see #retrieveSecurityLogs |
| 7296 | */ |
| 7297 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7298 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7299 | try { |
| 7300 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 7301 | } catch (RemoteException re) { |
| 7302 | throw re.rethrowFromSystemServer(); |
| 7303 | } |
| 7304 | } |
| 7305 | |
| 7306 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7307 | * Return whether security logging is enabled or not by the device owner. |
| 7308 | * |
| 7309 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 7310 | * thrown. |
| 7311 | * |
| 7312 | * @param admin Which device owner this request is associated with. |
| 7313 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 7314 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7315 | */ |
Bartosz Fabianowski | 0ec0000 | 2017-03-24 14:22:24 +0100 | [diff] [blame] | 7316 | public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7317 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7318 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7319 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7320 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7321 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7322 | } |
| 7323 | } |
| 7324 | |
| 7325 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7326 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 7327 | * this API after device boots. |
| 7328 | * |
| 7329 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 7330 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 7331 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7332 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7333 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7334 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7335 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7336 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7337 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 7338 | * 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] | 7339 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7340 | * profile or secondary user that is not affiliated with the device owner user. |
| 7341 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7342 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7343 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7344 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7345 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7346 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7347 | if (list != null) { |
| 7348 | return list.getList(); |
| 7349 | } else { |
| 7350 | // Rate limit exceeded. |
| 7351 | return null; |
| 7352 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7353 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7354 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7355 | } |
| 7356 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7357 | |
| 7358 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7359 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7360 | * profile. |
| 7361 | * |
| 7362 | * @hide |
| 7363 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7364 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7365 | mContext.checkSelfPermission( |
| 7366 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7367 | if (!uInfo.isManagedProfile()) { |
| 7368 | throw new SecurityException("The user " + uInfo.id |
| 7369 | + " does not have a parent profile."); |
| 7370 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7371 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7372 | } |
| 7373 | |
| 7374 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7375 | * 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] | 7376 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7377 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7378 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7379 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7380 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7381 | * |
| 7382 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7383 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7384 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7385 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7386 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7387 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7388 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7389 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7390 | * profile or secondary user that is not affiliated with the device owner user. |
| 7391 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7392 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7393 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7394 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7395 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7396 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7397 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7398 | if (list != null) { |
| 7399 | return list.getList(); |
| 7400 | } else { |
| 7401 | return null; |
| 7402 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7403 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7404 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7409 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7410 | * 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] | 7411 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7412 | * <p> |
| 7413 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7414 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7415 | * |
| 7416 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7417 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7418 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7419 | */ |
| 7420 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7421 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7422 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7423 | // always enforce alpha channel to have 100% opacity |
| 7424 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7425 | mService.setOrganizationColor(admin, color); |
| 7426 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7427 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7428 | } |
| 7429 | } |
| 7430 | |
| 7431 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7432 | * @hide |
| 7433 | * |
| 7434 | * Sets the color used for customization. |
| 7435 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7436 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7437 | * @param userId which user to set the color to. |
| 7438 | * @RequiresPermission(allOf = { |
| 7439 | * Manifest.permission.MANAGE_USERS, |
| 7440 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7441 | */ |
| 7442 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7443 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7444 | // always enforce alpha channel to have 100% opacity |
| 7445 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7446 | mService.setOrganizationColorForUser(color, userId); |
| 7447 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7448 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7449 | } |
| 7450 | } |
| 7451 | |
| 7452 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7453 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7454 | * This color is used as background color of the confirm credentials screen for that user. |
| 7455 | * |
| 7456 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7457 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7458 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7459 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7460 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7461 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7462 | try { |
| 7463 | return mService.getOrganizationColor(admin); |
| 7464 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7465 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7466 | } |
| 7467 | } |
| 7468 | |
| 7469 | /** |
| 7470 | * @hide |
| 7471 | * Retrieve the customization color for a given user. |
| 7472 | * |
| 7473 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7474 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7475 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7476 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7477 | try { |
| 7478 | return mService.getOrganizationColorForUser(userHandle); |
| 7479 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7480 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7481 | } |
| 7482 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7483 | |
| 7484 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7485 | * Called by the device owner or profile owner to set the name of the organization under |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7486 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7487 | * <p> |
| 7488 | * If the organization name needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7489 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7490 | * and set a new version of this string accordingly. |
| 7491 | * |
| 7492 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7493 | * @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] | 7494 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7495 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7496 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7497 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7498 | try { |
| 7499 | mService.setOrganizationName(admin, title); |
| 7500 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7501 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7502 | } |
| 7503 | } |
| 7504 | |
| 7505 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7506 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7507 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7508 | * |
| 7509 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7510 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7511 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7512 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7513 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7514 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7515 | try { |
| 7516 | return mService.getOrganizationName(admin); |
| 7517 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7518 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7519 | } |
| 7520 | } |
| 7521 | |
| 7522 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7523 | * Called by the system to retrieve the name of the organization managing the device. |
| 7524 | * |
| 7525 | * @return The organization name or {@code null} if none is set. |
| 7526 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7527 | * MANAGE_USERS permission and is not the system. |
| 7528 | * |
| 7529 | * @hide |
| 7530 | */ |
| 7531 | @SystemApi |
| 7532 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 7533 | @SuppressLint("Doclava125") |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7534 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7535 | try { |
| 7536 | return mService.getDeviceOwnerOrganizationName(); |
| 7537 | } catch (RemoteException re) { |
| 7538 | throw re.rethrowFromSystemServer(); |
| 7539 | } |
| 7540 | } |
| 7541 | |
| 7542 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7543 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7544 | * |
| 7545 | * @param userHandle The user id of the user we're interested in. |
| 7546 | * @return The organization name or {@code null} if none is set. |
| 7547 | * |
| 7548 | * @hide |
| 7549 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7550 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7551 | try { |
| 7552 | return mService.getOrganizationNameForUser(userHandle); |
| 7553 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7554 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7555 | } |
| 7556 | } |
| 7557 | |
| 7558 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7559 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7560 | * return {@link #STATE_USER_UNMANAGED} |
| 7561 | * @hide |
| 7562 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7563 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7564 | @UserProvisioningState |
| 7565 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7566 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7567 | if (mService != null) { |
| 7568 | try { |
| 7569 | return mService.getUserProvisioningState(); |
| 7570 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7571 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7572 | } |
| 7573 | } |
| 7574 | return STATE_USER_UNMANAGED; |
| 7575 | } |
| 7576 | |
| 7577 | /** |
| 7578 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7579 | * |
| 7580 | * @param state to store |
| 7581 | * @param userHandle for user |
| 7582 | * @hide |
| 7583 | */ |
| 7584 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7585 | if (mService != null) { |
| 7586 | try { |
| 7587 | mService.setUserProvisioningState(state, userHandle); |
| 7588 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7589 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7590 | } |
| 7591 | } |
| 7592 | } |
| 7593 | |
| 7594 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7595 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7596 | * 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] | 7597 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7598 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7599 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7600 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7601 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7602 | * created. |
| 7603 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7604 | * @param admin Which profile or device owner this request is associated with. |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7605 | * @param ids A set of opaque non-empty affiliation ids. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7606 | * |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7607 | * @throws IllegalArgumentException if {@code ids} is null or contains an empty string. |
| 7608 | */ |
| 7609 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) { |
| 7610 | throwIfParentInstance("setAffiliationIds"); |
| 7611 | if (ids == null) { |
| 7612 | throw new IllegalArgumentException("ids must not be null"); |
| 7613 | } |
| 7614 | try { |
| 7615 | mService.setAffiliationIds(admin, new ArrayList<>(ids)); |
| 7616 | } catch (RemoteException e) { |
| 7617 | throw e.rethrowFromSystemServer(); |
| 7618 | } |
| 7619 | } |
| 7620 | |
| 7621 | /** |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7622 | * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7623 | * empty set if none have been set. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7624 | */ |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7625 | public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) { |
Tony Mak | 62cf586 | 2017-05-02 13:50:18 +0100 | [diff] [blame] | 7626 | throwIfParentInstance("getAffiliationIds"); |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7627 | try { |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7628 | return new ArraySet<>(mService.getAffiliationIds(admin)); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7629 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7630 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7631 | } |
| 7632 | } |
| 7633 | |
| 7634 | /** |
| 7635 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7636 | * Returns whether this user/profile is affiliated with the device. |
| 7637 | * <p> |
| 7638 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7639 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7640 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7641 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7642 | */ |
| 7643 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7644 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7645 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7646 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7647 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7648 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7649 | } |
| 7650 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7651 | |
| 7652 | /** |
| 7653 | * @hide |
| 7654 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7655 | * to be started |
| 7656 | * @param packageName the package to check for |
| 7657 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7658 | */ |
| 7659 | public boolean isUninstallInQueue(String packageName) { |
| 7660 | try { |
| 7661 | return mService.isUninstallInQueue(packageName); |
| 7662 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7663 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7664 | } |
| 7665 | } |
| 7666 | |
| 7667 | /** |
| 7668 | * @hide |
| 7669 | * @param packageName the package containing active DAs to be uninstalled |
| 7670 | */ |
| 7671 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7672 | try { |
| 7673 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7674 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7675 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7676 | } |
| 7677 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7678 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7679 | /** |
| 7680 | * @hide |
| 7681 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7682 | * If the admin is a profile owner or device owner it will still be removed. |
| 7683 | * |
| 7684 | * @param userHandle user id to remove the admin for. |
| 7685 | * @param admin The administration compononent to remove. |
| 7686 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7687 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7688 | */ |
| 7689 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7690 | try { |
| 7691 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7692 | } catch (RemoteException re) { |
| 7693 | throw re.rethrowFromSystemServer(); |
| 7694 | } |
| 7695 | } |
| 7696 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7697 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7698 | * Returns whether the device has been provisioned. |
| 7699 | * |
| 7700 | * <p>Not for use by third-party applications. |
| 7701 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7702 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7703 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7704 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7705 | public boolean isDeviceProvisioned() { |
| 7706 | try { |
| 7707 | return mService.isDeviceProvisioned(); |
| 7708 | } catch (RemoteException re) { |
| 7709 | throw re.rethrowFromSystemServer(); |
| 7710 | } |
| 7711 | } |
| 7712 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7713 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7714 | * Writes that the provisioning configuration has been applied. |
| 7715 | * |
| 7716 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7717 | * permission. |
| 7718 | * |
| 7719 | * <p>Not for use by third-party applications. |
| 7720 | * |
| 7721 | * @hide |
| 7722 | */ |
| 7723 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7724 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7725 | public void setDeviceProvisioningConfigApplied() { |
| 7726 | try { |
| 7727 | mService.setDeviceProvisioningConfigApplied(); |
| 7728 | } catch (RemoteException re) { |
| 7729 | throw re.rethrowFromSystemServer(); |
| 7730 | } |
| 7731 | } |
| 7732 | |
| 7733 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7734 | * Returns whether the provisioning configuration has been applied. |
| 7735 | * |
| 7736 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7737 | * |
| 7738 | * <p>Not for use by third-party applications. |
| 7739 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7740 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7741 | * |
| 7742 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7743 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7744 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame^] | 7745 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7746 | public boolean isDeviceProvisioningConfigApplied() { |
| 7747 | try { |
| 7748 | return mService.isDeviceProvisioningConfigApplied(); |
| 7749 | } catch (RemoteException re) { |
| 7750 | throw re.rethrowFromSystemServer(); |
| 7751 | } |
| 7752 | } |
| 7753 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7754 | /** |
| 7755 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7756 | * Force update user setup completed status. This API has no effect on user build. |
| 7757 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7758 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7759 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7760 | */ |
| 7761 | public void forceUpdateUserSetupComplete() { |
| 7762 | try { |
| 7763 | mService.forceUpdateUserSetupComplete(); |
| 7764 | } catch (RemoteException re) { |
| 7765 | throw re.rethrowFromSystemServer(); |
| 7766 | } |
| 7767 | } |
| 7768 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7769 | private void throwIfParentInstance(String functionName) { |
| 7770 | if (mParentInstance) { |
| 7771 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7772 | } |
| 7773 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7774 | |
| 7775 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7776 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7777 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7778 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 7779 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7780 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7781 | * <p> Backup service is off by default when device owner is present. |
| 7782 | * |
Rubin Xu | 0367f07 | 2017-04-24 20:17:16 +0100 | [diff] [blame] | 7783 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7784 | * @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] | 7785 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7786 | */ |
| 7787 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7788 | throwIfParentInstance("setBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7789 | try { |
| 7790 | mService.setBackupServiceEnabled(admin, enabled); |
| 7791 | } catch (RemoteException re) { |
| 7792 | throw re.rethrowFromSystemServer(); |
| 7793 | } |
| 7794 | } |
| 7795 | |
| 7796 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7797 | * Return whether the backup service is enabled by the device owner. |
| 7798 | * |
| 7799 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 7800 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7801 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7802 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7803 | */ |
| 7804 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7805 | throwIfParentInstance("isBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7806 | try { |
| 7807 | return mService.isBackupServiceEnabled(admin); |
| 7808 | } catch (RemoteException re) { |
| 7809 | throw re.rethrowFromSystemServer(); |
| 7810 | } |
| 7811 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7812 | |
| 7813 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7814 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7815 | * |
Robin Lee | a40a2fb | 2017-02-08 17:07:06 +0000 | [diff] [blame] | 7816 | * <p> Network logs contain DNS lookup and connect() library call events. The following library |
| 7817 | * functions are recorded while network logging is active: |
| 7818 | * <ul> |
| 7819 | * <li>{@code getaddrinfo()}</li> |
| 7820 | * <li>{@code gethostbyname()}</li> |
| 7821 | * <li>{@code connect()}</li> |
| 7822 | * </ul> |
| 7823 | * |
| 7824 | * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use |
| 7825 | * full system call logging; event reporting is enabled by default for all processes but not |
| 7826 | * strongly enforced. |
| 7827 | * Events from applications using alternative implementations of libc, making direct kernel |
| 7828 | * calls, or deliberately obfuscating traffic may not be recorded. |
| 7829 | * |
| 7830 | * <p> Some common network events may not be reported. For example: |
| 7831 | * <ul> |
| 7832 | * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use |
| 7833 | * an alternative system for name resolution, and so avoid calling |
| 7834 | * {@code getaddrinfo()} or {@code gethostbyname}.</li> |
| 7835 | * <li>Applications may use datagram sockets for performance reasons, for example |
| 7836 | * for a game client. Calling {@code connect()} is unnecessary for this kind of |
| 7837 | * socket, so it will not trigger a network event.</li> |
| 7838 | * </ul> |
| 7839 | * |
| 7840 | * <p> It is possible to directly intercept layer 3 traffic leaving the device using an |
| 7841 | * always-on VPN service. |
| 7842 | * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} |
| 7843 | * and {@link android.net.VpnService} for details. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7844 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7845 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7846 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7847 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7848 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7849 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7850 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7851 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7852 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7853 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7854 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7855 | */ |
| 7856 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7857 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7858 | try { |
| 7859 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7860 | } catch (RemoteException re) { |
| 7861 | throw re.rethrowFromSystemServer(); |
| 7862 | } |
| 7863 | } |
| 7864 | |
| 7865 | /** |
| 7866 | * Return whether network logging is enabled by a device owner. |
| 7867 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7868 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7869 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7870 | * @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] | 7871 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7872 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7873 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7874 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7875 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7876 | try { |
| 7877 | return mService.isNetworkLoggingEnabled(admin); |
| 7878 | } catch (RemoteException re) { |
| 7879 | throw re.rethrowFromSystemServer(); |
| 7880 | } |
| 7881 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7882 | |
| 7883 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7884 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7885 | * A device owner has to provide a batchToken provided as part of |
| 7886 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7887 | * 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] | 7888 | * |
| 7889 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7890 | * |
| 7891 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7892 | * |
| 7893 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7894 | * after the device device owner has been notified via |
| 7895 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7896 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7897 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7898 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7899 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7900 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7901 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7902 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7903 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7904 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7905 | * @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] | 7906 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7907 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7908 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7909 | * 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] | 7910 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7911 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7912 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7913 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7914 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7915 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7916 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7917 | } catch (RemoteException re) { |
| 7918 | throw re.rethrowFromSystemServer(); |
| 7919 | } |
| 7920 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7921 | |
| 7922 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7923 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 7924 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7925 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7926 | * <p> |
Tony Mak | eda0a9a | 2017-04-25 12:07:14 +0100 | [diff] [blame] | 7927 | * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
| 7928 | * Note that the {@link Context} used to obtain this |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7929 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7930 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7931 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7932 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7933 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7934 | * explicit component name or a package name to match an |
| 7935 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7936 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7937 | * 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] | 7938 | * @param flags Operation options for the binding operation. See |
| 7939 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7940 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7941 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7942 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7943 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7944 | * {@code false} is returned if the connection is not made and you will not |
| 7945 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7946 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7947 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7948 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7949 | */ |
| 7950 | public boolean bindDeviceAdminServiceAsUser( |
| 7951 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7952 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7953 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7954 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7955 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7956 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 7957 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7958 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7959 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7960 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7961 | sd, flags, targetUser.getIdentifier()); |
| 7962 | } catch (RemoteException re) { |
| 7963 | throw re.rethrowFromSystemServer(); |
| 7964 | } |
| 7965 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7966 | |
| 7967 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7968 | * Returns the list of target users that the calling device or profile owner can use when |
| 7969 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 7970 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7971 | * 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] | 7972 | * <ul> |
| 7973 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7974 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7975 | * </ul> |
| 7976 | */ |
| 7977 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 7978 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 7979 | try { |
| 7980 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 7981 | } catch (RemoteException re) { |
| 7982 | throw re.rethrowFromSystemServer(); |
| 7983 | } |
| 7984 | } |
| 7985 | |
| 7986 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7987 | * Called by the system to get the time at which the device owner last retrieved security |
| 7988 | * logging entries. |
| 7989 | * |
| 7990 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 7991 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7992 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7993 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7994 | * |
| 7995 | * @hide |
| 7996 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7997 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7998 | public long getLastSecurityLogRetrievalTime() { |
| 7999 | try { |
| 8000 | return mService.getLastSecurityLogRetrievalTime(); |
| 8001 | } catch (RemoteException re) { |
| 8002 | throw re.rethrowFromSystemServer(); |
| 8003 | } |
| 8004 | } |
| 8005 | |
| 8006 | /** |
| 8007 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 8008 | * |
| 8009 | * @return the time at which the device owner most recently requested a bug report, in |
| 8010 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8011 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8012 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8013 | * |
| 8014 | * @hide |
| 8015 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8016 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8017 | public long getLastBugReportRequestTime() { |
| 8018 | try { |
| 8019 | return mService.getLastBugReportRequestTime(); |
| 8020 | } catch (RemoteException re) { |
| 8021 | throw re.rethrowFromSystemServer(); |
| 8022 | } |
| 8023 | } |
| 8024 | |
| 8025 | /** |
| 8026 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 8027 | * events. |
| 8028 | * |
| 8029 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 8030 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8031 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8032 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8033 | * |
| 8034 | * @hide |
| 8035 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8036 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8037 | public long getLastNetworkLogRetrievalTime() { |
| 8038 | try { |
| 8039 | return mService.getLastNetworkLogRetrievalTime(); |
| 8040 | } catch (RemoteException re) { |
| 8041 | throw re.rethrowFromSystemServer(); |
| 8042 | } |
| 8043 | } |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8044 | |
| 8045 | /** |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8046 | * Called by the system to find out whether the current user's IME was set by the device/profile |
| 8047 | * owner or the user. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8048 | * |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8049 | * @return {@code true} if the user's IME was set by the device or profile owner, {@code false} |
| 8050 | * otherwise. |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8051 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8052 | * |
| 8053 | * @hide |
| 8054 | */ |
| 8055 | @TestApi |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8056 | public boolean isCurrentInputMethodSetByOwner() { |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8057 | try { |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8058 | return mService.isCurrentInputMethodSetByOwner(); |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8059 | } catch (RemoteException re) { |
| 8060 | throw re.rethrowFromSystemServer(); |
| 8061 | } |
| 8062 | } |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8063 | |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8064 | /** |
| 8065 | * Called by the system to get a list of CA certificates that were installed by the device or |
| 8066 | * profile owner. |
| 8067 | * |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8068 | * <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] | 8069 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 8070 | * |
| 8071 | * @param user The user for whom to retrieve information. |
| 8072 | * @return list of aliases identifying CA certificates installed by the device or profile owner |
| 8073 | * @throws SecurityException if the caller does not have permission to retrieve information |
| 8074 | * about the given user's CA certificates. |
| 8075 | * |
| 8076 | * @hide |
| 8077 | */ |
| 8078 | @TestApi |
| 8079 | public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) { |
| 8080 | try { |
| 8081 | return mService.getOwnerInstalledCaCerts(user).getList(); |
| 8082 | } catch (RemoteException re) { |
| 8083 | throw re.rethrowFromSystemServer(); |
| 8084 | } |
| 8085 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 8086 | } |