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; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 58 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 59 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 60 | import android.telephony.TelephonyManager; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 61 | import android.util.ArraySet; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 62 | import android.util.Log; |
| 63 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 64 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 65 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 66 | |
| 67 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 68 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 69 | import java.lang.annotation.Retention; |
| 70 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 71 | import java.net.InetSocketAddress; |
| 72 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 73 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 74 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 75 | import java.security.PrivateKey; |
| 76 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 77 | import java.security.cert.CertificateException; |
| 78 | import java.security.cert.CertificateFactory; |
| 79 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 80 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 81 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 82 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 83 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 84 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 85 | import java.util.List; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 86 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 89 | * 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] | 90 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 91 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 92 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 93 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 94 | * application calling an api may only pass as an argument a device administrator component it |
| 95 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 96 | * <div class="special reference"> |
| 97 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 98 | * <p> |
| 99 | * For more information about managing policies for device administration, read the <a href= |
| 100 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 101 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 102 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 103 | @SystemService(Context.DEVICE_POLICY_SERVICE) |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 104 | public class DevicePolicyManager { |
| 105 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 106 | |
| 107 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 108 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 109 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 110 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 111 | /** @hide */ |
| 112 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 113 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 116 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 118 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 119 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | mContext = context; |
| 121 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 122 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 125 | /** @hide test will override it. */ |
| 126 | @VisibleForTesting |
| 127 | protected int myUserId() { |
| 128 | return UserHandle.myUserId(); |
| 129 | } |
| 130 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 131 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 132 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 133 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 134 | * <p>A managed profile allows data separation for example for the usage of a |
| 135 | * device as a personal and corporate device. The user which provisioning is started from and |
| 136 | * the managed profile share a launcher. |
| 137 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 138 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 139 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 140 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 141 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 142 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 143 | * {@link #isProvisioningAllowed(String)}. |
| 144 | * |
| 145 | * <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] | 146 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 147 | * 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] | 148 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 149 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 150 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 151 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 152 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 153 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 154 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 155 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 156 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 157 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 158 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 159 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 160 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 161 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 162 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 163 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 164 | * <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] | 165 | * in the provisioning intent. The |
| 166 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 167 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 168 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 169 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 170 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 171 | * completed, along with the above broadcast, activity intent |
| 172 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in |
| 173 | * the provisioning intent. |
| 174 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 175 | * <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] | 176 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 177 | * |
| 178 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 179 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 180 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 181 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 182 | * 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] | 183 | */ |
| 184 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 185 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 186 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 187 | |
| 188 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 189 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 190 | * |
| 191 | * <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] | 192 | * 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] | 193 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 194 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 195 | * allowed. |
| 196 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 197 | * <p>The intent contains the following extras: |
| 198 | * <ul> |
| 199 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 200 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 201 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 202 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 203 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 204 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 205 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 206 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 207 | * |
| 208 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 209 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 210 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 211 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 212 | * 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] | 213 | * |
| 214 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 215 | */ |
| 216 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 217 | public static final String ACTION_PROVISION_MANAGED_USER |
| 218 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 219 | |
| 220 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 221 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 222 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 223 | * |
| 224 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 225 | * A device owner has full control over the device. The device owner can not be modified by the |
| 226 | * user. |
| 227 | * |
| 228 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 229 | * employee or client. |
| 230 | * |
| 231 | * <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] | 232 | * It is possible to check if provisioning is allowed or not by querying the method |
| 233 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 234 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 235 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 236 | * <ul> |
| 237 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 238 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 239 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 240 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 241 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 242 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 243 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 244 | * </ul> |
| 245 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 246 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 247 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 248 | * device owner. |
| 249 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 250 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 251 | * completed, along with the above broadcast, activity intent |
| 252 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 253 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 254 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 255 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 256 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 257 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 258 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 259 | * 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] | 260 | */ |
| 261 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 262 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 263 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 264 | |
| 265 | /** |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 266 | * Activity action: launch when user provisioning completed, i.e. |
| 267 | * {@link #getUserProvisioningState()} returns one of the complete state. |
| 268 | * |
| 269 | * <p> Please note that the API behavior is not necessarily consistent across various releases, |
| 270 | * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default |
| 271 | * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only. |
| 272 | * |
| 273 | * <p> The activity must be protected by permission |
| 274 | * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold |
| 275 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched. |
| 276 | * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the |
| 277 | * components are not started by this intent. |
| 278 | * @hide |
| 279 | */ |
| 280 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 281 | public static final String ACTION_STATE_USER_SETUP_COMPLETE = |
| 282 | "android.app.action.STATE_USER_SETUP_COMPLETE"; |
| 283 | |
| 284 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 285 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 286 | * |
| 287 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 288 | * the device. A device owner has full control over the device. The device owner can not be |
| 289 | * modified by the user and the only way of resetting the device is via factory reset. |
| 290 | * |
| 291 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 292 | * employee or client. |
| 293 | * |
| 294 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 295 | * |
| 296 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 297 | * by a privileged app with the permission |
| 298 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 299 | * |
| 300 | * <p>The provisioning intent contains the following properties: |
| 301 | * <ul> |
| 302 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 303 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 304 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 305 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 306 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 307 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 308 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 309 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 310 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 312 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 314 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 315 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 316 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 317 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 318 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 319 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 320 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 321 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 322 | * |
| 323 | * @hide |
| 324 | */ |
| 325 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 326 | @SystemApi |
| 327 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 328 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 329 | |
| 330 | /** |
| 331 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 332 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 333 | * |
| 334 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 335 | * management state that is distinct from that reached by |
| 336 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 337 | * user, and only has control over device-wide policies, not individual users and their data. |
| 338 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 339 | * this form of device management. |
| 340 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 341 | * <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] | 342 | * A device owner has full control over the device. The device owner can not be modified by the |
| 343 | * user. |
| 344 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 345 | * <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] | 346 | * employee or client. |
| 347 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 348 | * <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] | 349 | * It is possible to check if provisioning is allowed or not by querying the method |
| 350 | * {@link #isProvisioningAllowed(String)}. |
| 351 | * |
| 352 | * <p>The intent contains the following extras: |
| 353 | * <ul> |
| 354 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 355 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 356 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 357 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 358 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 359 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 360 | * </ul> |
| 361 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 362 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 363 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 364 | * device owner. |
| 365 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 366 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 367 | * completed, along with the above broadcast, activity intent |
| 368 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 369 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 370 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 371 | * |
| 372 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 373 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 374 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 375 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 376 | * |
| 377 | * @hide |
| 378 | */ |
| 379 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 380 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 381 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 382 | |
| 383 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 384 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 385 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 386 | * <ul> |
| 387 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 388 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 389 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 390 | * </ul> |
| 391 | * |
| 392 | * @hide |
| 393 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 394 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 395 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 396 | public static final String ACTION_PROVISION_FINALIZATION |
| 397 | = "android.app.action.PROVISION_FINALIZATION"; |
| 398 | |
| 399 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 400 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 401 | * |
| 402 | * @hide |
| 403 | */ |
| 404 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 405 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 406 | |
| 407 | /** |
| 408 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 409 | * |
| 410 | * @hide |
| 411 | */ |
| 412 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 413 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 414 | |
| 415 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 416 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 417 | * |
| 418 | * @hide |
| 419 | */ |
| 420 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 421 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 422 | |
| 423 | /** |
| 424 | * Extra for shared bugreport's SHA-256 hash. |
| 425 | * |
| 426 | * @hide |
| 427 | */ |
| 428 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 429 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 430 | |
| 431 | /** |
| 432 | * Extra for remote bugreport notification shown type. |
| 433 | * |
| 434 | * @hide |
| 435 | */ |
| 436 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 437 | "android.app.extra.bugreport_notification_type"; |
| 438 | |
| 439 | /** |
| 440 | * Notification type for a started remote bugreport flow. |
| 441 | * |
| 442 | * @hide |
| 443 | */ |
| 444 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 445 | |
| 446 | /** |
| 447 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 448 | * being taken. |
| 449 | * |
| 450 | * @hide |
| 451 | */ |
| 452 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 453 | |
| 454 | /** |
| 455 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 456 | * |
| 457 | * @hide |
| 458 | */ |
| 459 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 460 | |
| 461 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 462 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 463 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 464 | * |
| 465 | * @hide |
| 466 | */ |
| 467 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 468 | |
| 469 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 470 | * 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] | 471 | * allows a mobile device management application or NFC programmer application which starts |
| 472 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 473 | * <p> |
| 474 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 475 | * sends the intent to pass data to itself on the newly created profile. |
| 476 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 477 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 478 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 479 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 480 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 481 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 482 | * management application after provisioning. |
| 483 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 484 | * <p> |
| 485 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 486 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 487 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 488 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 489 | */ |
| 490 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 491 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 492 | |
| 493 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 494 | * A String extra holding the package name of the mobile device management application that |
| 495 | * will be set as the profile owner or device owner. |
| 496 | * |
| 497 | * <p>If an application starts provisioning directly via an intent with action |
| 498 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 499 | * application that started provisioning. The package will be set as profile owner in that case. |
| 500 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 501 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 502 | * 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] | 503 | * |
| 504 | * <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] | 505 | * 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] | 506 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 507 | * @see DeviceAdminReceiver |
| 508 | * @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] | 509 | * supported, but only if there is only one device admin receiver in the package that requires |
| 510 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 511 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 512 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 513 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 514 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 515 | |
| 516 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 517 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 518 | * application that will be set as the profile owner or device owner and active admin. |
| 519 | * |
| 520 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 521 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 522 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 523 | * 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] | 524 | * |
| 525 | * <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] | 526 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 527 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 528 | * {@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] | 529 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 530 | * |
| 531 | * @see DeviceAdminReceiver |
| 532 | */ |
| 533 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 534 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 535 | |
| 536 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 537 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 538 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 539 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 540 | * |
| 541 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 542 | */ |
| 543 | |
| 544 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 545 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 546 | |
| 547 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 548 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 549 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 550 | * the account will not be removed from the primary user after it is migrated to the newly |
| 551 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 552 | * |
| 553 | * <p> Defaults to {@code false} |
| 554 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 555 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 556 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 557 | */ |
| 558 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 559 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 560 | |
| 561 | /** |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 562 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the |
| 563 | * device. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 564 | */ |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 565 | @Deprecated |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 566 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 567 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 568 | |
| 569 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 570 | * A integer extra indicating the predominant color to show during the provisioning. |
| 571 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 572 | * |
| 573 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 574 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 575 | */ |
| 576 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 577 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 578 | |
| 579 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 580 | * 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] | 581 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 582 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 583 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 584 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 585 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 586 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 587 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 588 | |
| 589 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 590 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 591 | * will be set to. |
| 592 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 593 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 594 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 595 | */ |
| 596 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 597 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 598 | |
| 599 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 600 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 601 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 603 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 604 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 605 | */ |
| 606 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 607 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 608 | |
| 609 | /** |
| 610 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 611 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 612 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 613 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 614 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 615 | */ |
| 616 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 617 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 618 | |
| 619 | /** |
| 620 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 621 | * owner provisioning for downloading the mobile device management application. |
| 622 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 623 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 624 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 625 | */ |
| 626 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 627 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 628 | |
| 629 | /** |
| 630 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 631 | * is hidden or not. |
| 632 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 633 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 634 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 635 | */ |
| 636 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 637 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 638 | |
| 639 | /** |
| 640 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 641 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 642 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 643 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 644 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 645 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 646 | */ |
| 647 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 648 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 649 | |
| 650 | /** |
| 651 | * A String extra holding the password of the wifi network in |
| 652 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 653 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 654 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 655 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 656 | */ |
| 657 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 658 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 659 | |
| 660 | /** |
| 661 | * A String extra holding the proxy host for the wifi network in |
| 662 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 663 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 664 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 665 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 666 | */ |
| 667 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 668 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * An int extra holding the proxy port for the wifi network in |
| 672 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 673 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 674 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 675 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 676 | */ |
| 677 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 678 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 679 | |
| 680 | /** |
| 681 | * A String extra holding the proxy bypass for the wifi network in |
| 682 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 683 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 684 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 685 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 686 | */ |
| 687 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 688 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 689 | |
| 690 | /** |
| 691 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 692 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 693 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 694 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 695 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 696 | */ |
| 697 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 698 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 699 | |
| 700 | /** |
| 701 | * A String extra holding a url that specifies the download location of the device admin |
| 702 | * package. When not provided it is assumed that the device admin package is already installed. |
| 703 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 704 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 705 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 706 | */ |
| 707 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 708 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 709 | |
| 710 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 711 | * A String extra holding the localized name of the organization under management. |
| 712 | * |
| 713 | * The name is displayed only during provisioning. |
| 714 | * |
| 715 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 716 | * |
| 717 | * @hide |
| 718 | */ |
| 719 | @SystemApi |
| 720 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 721 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 722 | |
| 723 | /** |
Alejandro Fernández | bfd6193 | 2017-04-04 19:33:01 +0100 | [diff] [blame] | 724 | * A String extra holding a url to the website of the device provider so the user can open it |
| 725 | * 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] | 726 | * |
| 727 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 728 | * |
| 729 | * @hide |
| 730 | */ |
| 731 | @SystemApi |
| 732 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 733 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 734 | |
| 735 | /** |
| 736 | * A String extra holding the localized name of the device admin package. It should be the same |
| 737 | * as the app label of the package. |
| 738 | * |
| 739 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 740 | * |
| 741 | * @hide |
| 742 | */ |
| 743 | @SystemApi |
| 744 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 745 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 746 | |
| 747 | /** |
| 748 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 749 | * shown during the provisioning. |
| 750 | * <h5>The following URI schemes are accepted:</h5> |
| 751 | * <ul> |
| 752 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 753 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 754 | * </ul> |
| 755 | * |
| 756 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 757 | * pixel density for the device. |
| 758 | * |
| 759 | * <p> If a content: URI is passed, the intent should have the flag |
| 760 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 761 | * {@link android.content.ClipData} of the intent too. |
| 762 | * |
| 763 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 764 | * |
| 765 | * @hide |
| 766 | */ |
| 767 | @SystemApi |
| 768 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 769 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 770 | |
| 771 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 772 | * An int extra holding a minimum required version code for the device admin package. If the |
| 773 | * device admin is already installed on the device, it will only be re-downloaded from |
| 774 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 775 | * installed package is less than this version code. |
| 776 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 777 | * <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] | 778 | * provisioning via an NFC bump. |
| 779 | */ |
| 780 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 781 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 782 | |
| 783 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 784 | * A String extra holding a http cookie header which should be used in the http request to the |
| 785 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 786 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 787 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 788 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 789 | */ |
| 790 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 791 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 792 | |
| 793 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 794 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 795 | * the file at download location specified in |
| 796 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 797 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 798 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 799 | * 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] | 800 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 801 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 802 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 803 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 804 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 805 | * |
| 806 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 807 | * 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] | 808 | * 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] | 809 | * 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] | 810 | */ |
| 811 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 812 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 813 | |
| 814 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 815 | * 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] | 816 | * android package archive at the download location specified in {@link |
| 817 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 818 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 819 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 820 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 821 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 822 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 823 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 824 | * 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] | 825 | * the download location. If the checksum does not match an error will be shown to the user and |
| 826 | * the user will be asked to factory reset the device. |
| 827 | * |
| 828 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 829 | * provisioning via an NFC bump. |
| 830 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 831 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 832 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 833 | |
| 834 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 835 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 836 | * has completed successfully. |
| 837 | * |
| 838 | * <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] | 839 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 840 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 841 | * <p>This intent will contain the following extras |
| 842 | * <ul> |
| 843 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 844 | * profile.</li> |
| 845 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 846 | * be migrated at provisioning time, if any.</li> |
| 847 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 848 | */ |
| 849 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 850 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 851 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 852 | |
| 853 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 854 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 855 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 856 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 857 | * delivered faster as it's an activity intent. |
| 858 | * |
| 859 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 860 | * the device owner case the profile is the primary user. |
| 861 | * |
| 862 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 863 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 864 | */ |
| 865 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 866 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 867 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 868 | |
| 869 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 870 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 871 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 872 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 873 | * <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] | 874 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 875 | * |
| 876 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 877 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 878 | */ |
| 879 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 880 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 881 | |
| 882 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 883 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 884 | * provisioning. If this extra is not passed, a default image will be shown. |
| 885 | * <h5>The following URI schemes are accepted:</h5> |
| 886 | * <ul> |
| 887 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 888 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 889 | * </ul> |
| 890 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 891 | * <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] | 892 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 893 | * |
| 894 | * <p> If a content: URI is passed, the intent should have the flag |
| 895 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 896 | * {@link android.content.ClipData} of the intent too. |
| 897 | * |
| 898 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 899 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 900 | */ |
| 901 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 902 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 903 | |
| 904 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 905 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 906 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 907 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 908 | * content. |
| 909 | * |
| 910 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 911 | * management application (MDM), and one disclaimer from the organization. |
| 912 | * |
| 913 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 914 | * |
| 915 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 916 | * |
| 917 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 918 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 919 | */ |
| 920 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 921 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 922 | |
| 923 | /** |
| 924 | * A String extra of localized disclaimer header. |
| 925 | * |
| 926 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 927 | * or the organization name. |
| 928 | * |
| 929 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 930 | * |
| 931 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 932 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 933 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 934 | * |
| 935 | * <pre> |
| 936 | * <meta-data |
| 937 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 938 | * android:resource="@string/disclaimer_header" |
| 939 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 940 | */ |
| 941 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 942 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 943 | |
| 944 | /** |
| 945 | * A {@link Uri} extra pointing to disclaimer content. |
| 946 | * |
| 947 | * <h5>The following URI schemes are accepted:</h5> |
| 948 | * <ul> |
| 949 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 950 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 951 | * </ul> |
| 952 | * |
| 953 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 954 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 955 | * {@link android.widget.TextView}. |
| 956 | * |
| 957 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 958 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 959 | * {@link android.content.ClipData} of the intent too. |
| 960 | * |
| 961 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 962 | * |
| 963 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 964 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 965 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 966 | * |
| 967 | * <pre> |
| 968 | * <meta-data |
| 969 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 970 | * android:resource="@string/disclaimer_content" |
| 971 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 972 | */ |
| 973 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 974 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 975 | |
| 976 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 977 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 978 | * during setup-wizard. |
| 979 | * |
| 980 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 981 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 982 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 983 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 984 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 985 | * |
| 986 | * @hide |
| 987 | */ |
| 988 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 989 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 990 | |
| 991 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 992 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 993 | * skipped. If unspecified, defaults to {@code false}. |
| 994 | * |
| 995 | * It can only be used by an existing device owner trying to create a managed profile via |
| 996 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 997 | */ |
| 998 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 999 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 1000 | |
| 1001 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1002 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1003 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 1004 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 1005 | * A device owner has full control over the device. The device owner can not be modified by the |
| 1006 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 1007 | * reset. |
| 1008 | * |
| 1009 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 1010 | * employee or client. |
| 1011 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1012 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1013 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 1014 | * <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] | 1015 | * contains the following properties: |
| 1016 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1017 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 1018 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 1019 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1020 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1021 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1022 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1023 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1024 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1025 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1026 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1027 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1028 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1029 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1030 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1031 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1032 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1033 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1034 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1035 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1036 | * 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] | 1037 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1038 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1039 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1040 | */ |
| 1041 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1042 | = "application/com.android.managedprovisioning"; |
| 1043 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1044 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1045 | * Activity action: ask the user to add a new device administrator to the system. |
| 1046 | * The desired policy is the ComponentName of the policy in the |
| 1047 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1048 | * bring the user through adding the device administrator to the system (or |
| 1049 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1050 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1051 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1052 | * field to provide the user with additional explanation (in addition |
| 1053 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1054 | * |
| 1055 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1056 | * user intervention). However, if your administrator has been updated and is requesting |
| 1057 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1058 | * 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] | 1059 | */ |
| 1060 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1061 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1062 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1063 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1064 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1065 | * @hide |
| 1066 | * 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] | 1067 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1068 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1069 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1070 | * 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] | 1071 | * to remotely control restrictions on the user. |
| 1072 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1073 | * <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] | 1074 | * result of whether or not the user approved the action. If approved, the result will |
| 1075 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1076 | * as a profile owner. |
| 1077 | * |
| 1078 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1079 | * field to provide the user with additional explanation (in addition |
| 1080 | * to your component's description) about what is being added. |
| 1081 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1082 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1083 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1084 | */ |
| 1085 | @SystemApi |
| 1086 | public static final String ACTION_SET_PROFILE_OWNER |
| 1087 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1088 | |
| 1089 | /** |
| 1090 | * @hide |
| 1091 | * Name of the profile owner admin that controls the user. |
| 1092 | */ |
| 1093 | @SystemApi |
| 1094 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1095 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1096 | |
| 1097 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1098 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1099 | * 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] | 1100 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1101 | * @hide |
| 1102 | */ |
| 1103 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1104 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1105 | |
| 1106 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1107 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1108 | * |
| 1109 | * This broadcast is sent only to the primary user. |
| 1110 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1111 | */ |
| 1112 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1113 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1114 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1115 | |
| 1116 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1117 | * The ComponentName of the administrator component. |
| 1118 | * |
| 1119 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1120 | */ |
| 1121 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1122 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1123 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1124 | * An optional CharSequence providing additional explanation for why the |
| 1125 | * admin is being added. |
| 1126 | * |
| 1127 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1128 | */ |
| 1129 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1130 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1131 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1132 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1133 | * {@link #createAdminSupportIntent(String)}. |
| 1134 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1135 | */ |
| 1136 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1137 | |
| 1138 | /** |
| 1139 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1140 | * {@link #createAdminSupportIntent(String)}. |
| 1141 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1142 | */ |
| 1143 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1144 | |
| 1145 | /** |
| 1146 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1147 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
| 1148 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 1149 | * @see #createAdminSupportIntent(String) |
| 1150 | * @hide |
| 1151 | */ |
| 1152 | @TestApi |
| 1153 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1154 | |
| 1155 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1156 | * Activity action: have the user enter a new password. This activity should |
| 1157 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1158 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1159 | * enter a new password that meets the current requirements. You can use |
| 1160 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1161 | * have the user select a new password in order to meet the current |
| 1162 | * constraints. Upon being resumed from this activity, you can check the new |
| 1163 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1164 | * |
| 1165 | * If the intent is launched from within a managed profile with a profile |
| 1166 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1167 | * this will trigger entering a new password for the parent of the profile. |
| 1168 | * For all other cases it will trigger entering a new password for the user |
| 1169 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1170 | * |
| 1171 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1172 | */ |
| 1173 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1174 | public static final String ACTION_SET_NEW_PASSWORD |
| 1175 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1176 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1177 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1178 | * Activity action: have the user enter a new password for the parent profile. |
| 1179 | * If the intent is launched from within a managed profile, this will trigger |
| 1180 | * entering a new password for the parent of the profile. In all other cases |
| 1181 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1182 | */ |
| 1183 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1184 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1185 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1186 | |
| 1187 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1188 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1189 | * Network logging was enabled and the user tapped the notification. |
| 1190 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1191 | * @hide |
| 1192 | */ |
| 1193 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1194 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1195 | |
| 1196 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1197 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1198 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1199 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1200 | * |
| 1201 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1202 | */ |
| 1203 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1204 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1205 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1206 | |
| 1207 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1208 | * 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] | 1209 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1210 | */ |
| 1211 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1212 | |
| 1213 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1214 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1215 | * the parent profile to access intents sent from the managed profile. |
| 1216 | * That is, when an app in the managed profile calls |
| 1217 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1218 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1219 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1220 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1221 | |
| 1222 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1223 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1224 | * the managed profile to access intents sent from the parent profile. |
| 1225 | * That is, when an app in the parent profile calls |
| 1226 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1227 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1228 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1229 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1230 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1231 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1232 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1233 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1234 | */ |
| 1235 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1236 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1237 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1238 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1239 | /** |
| 1240 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1241 | * Already granted or denied permissions are not affected by this. |
| 1242 | */ |
| 1243 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1244 | |
| 1245 | /** |
| 1246 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1247 | * Already granted or denied permissions are not affected by this. |
| 1248 | */ |
| 1249 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1250 | |
| 1251 | /** |
| 1252 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1253 | * Already granted or denied permissions are not affected by this. |
| 1254 | */ |
| 1255 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1256 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1257 | /** |
| 1258 | * Runtime permission state: The user can manage the permission |
| 1259 | * through the UI. |
| 1260 | */ |
| 1261 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1262 | |
| 1263 | /** |
| 1264 | * Runtime permission state: The permission is granted to the app |
| 1265 | * and the user cannot manage the permission through the UI. |
| 1266 | */ |
| 1267 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1268 | |
| 1269 | /** |
| 1270 | * Runtime permission state: The permission is denied to the app |
| 1271 | * and the user cannot manage the permission through the UI. |
| 1272 | */ |
| 1273 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1274 | |
| 1275 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1276 | * Delegation of certificate installation and management. This scope grants access to the |
| 1277 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1278 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1279 | */ |
| 1280 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1281 | |
| 1282 | /** |
| 1283 | * Delegation of application restrictions management. This scope grants access to the |
| 1284 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1285 | */ |
| 1286 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1287 | |
| 1288 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1289 | * Delegation of application uninstall block. This scope grants access to the |
| 1290 | * {@link #setUninstallBlocked} API. |
| 1291 | */ |
| 1292 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1293 | |
| 1294 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1295 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1296 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1297 | * and {@link #setPermissionGrantState} APIs. |
| 1298 | */ |
| 1299 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1300 | |
| 1301 | /** |
| 1302 | * Delegation of package access state. This scope grants access to the |
| 1303 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1304 | * {@link #setPackagesSuspended} APIs. |
| 1305 | */ |
| 1306 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1307 | |
| 1308 | /** |
| 1309 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1310 | * API. |
| 1311 | */ |
| 1312 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1313 | |
| 1314 | /** |
| 1315 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1316 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1317 | * @hide |
| 1318 | */ |
| 1319 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1320 | "delegation-keep-uninstalled-packages"; |
| 1321 | |
| 1322 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1323 | * No management for current user in-effect. This is the default. |
| 1324 | * @hide |
| 1325 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1326 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1327 | public static final int STATE_USER_UNMANAGED = 0; |
| 1328 | |
| 1329 | /** |
| 1330 | * Management partially setup, user setup needs to be completed. |
| 1331 | * @hide |
| 1332 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1333 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1334 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1335 | |
| 1336 | /** |
| 1337 | * Management partially setup, user setup completed. |
| 1338 | * @hide |
| 1339 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1340 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1341 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1342 | |
| 1343 | /** |
| 1344 | * Management setup and active on current user. |
| 1345 | * @hide |
| 1346 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1347 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1348 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1349 | |
| 1350 | /** |
| 1351 | * Management partially setup on a managed profile. |
| 1352 | * @hide |
| 1353 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1354 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1355 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1356 | |
| 1357 | /** |
| 1358 | * @hide |
| 1359 | */ |
| 1360 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1361 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1362 | @Retention(RetentionPolicy.SOURCE) |
| 1363 | public @interface UserProvisioningState {} |
| 1364 | |
| 1365 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1366 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1367 | * |
| 1368 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1369 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1370 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1371 | * |
| 1372 | * @hide |
| 1373 | */ |
| 1374 | public static final int CODE_OK = 0; |
| 1375 | |
| 1376 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1377 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1378 | * |
| 1379 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1380 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1381 | * owner. |
| 1382 | * |
| 1383 | * @hide |
| 1384 | */ |
| 1385 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1386 | |
| 1387 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1388 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1389 | * |
| 1390 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1391 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1392 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1393 | * |
| 1394 | * @hide |
| 1395 | */ |
| 1396 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1397 | |
| 1398 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1399 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1400 | * |
| 1401 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1402 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1403 | * |
| 1404 | * @hide |
| 1405 | */ |
| 1406 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1407 | |
| 1408 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1409 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1410 | * |
| 1411 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1412 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1413 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1414 | * |
| 1415 | * @hide |
| 1416 | */ |
| 1417 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1418 | |
| 1419 | /** |
| 1420 | * Code used to indicate that the device also has a user other than the system user. |
| 1421 | * |
| 1422 | * @hide |
| 1423 | */ |
| 1424 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1425 | |
| 1426 | /** |
| 1427 | * Code used to indicate that device has an account that prevents provisioning. |
| 1428 | * |
| 1429 | * @hide |
| 1430 | */ |
| 1431 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1432 | |
| 1433 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1434 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1435 | * |
| 1436 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1437 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1438 | * |
| 1439 | * @hide |
| 1440 | */ |
| 1441 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1442 | |
| 1443 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1444 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1445 | * |
| 1446 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1447 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1448 | * when the device is a watch and is already paired. |
| 1449 | * |
| 1450 | * @hide |
| 1451 | */ |
| 1452 | public static final int CODE_HAS_PAIRED = 8; |
| 1453 | |
| 1454 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1455 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1456 | * |
| 1457 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1458 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1459 | * |
| 1460 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1461 | * @hide |
| 1462 | */ |
| 1463 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1464 | |
| 1465 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1466 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1467 | * |
| 1468 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1469 | * |
| 1470 | * @hide |
| 1471 | */ |
| 1472 | public static final int CODE_SYSTEM_USER = 10; |
| 1473 | |
| 1474 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1475 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1476 | * |
| 1477 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1478 | * managed profiles. |
| 1479 | * |
| 1480 | * @hide |
| 1481 | */ |
| 1482 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1483 | |
| 1484 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1485 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1486 | * |
| 1487 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1488 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1489 | * user. |
| 1490 | * |
| 1491 | * @hide |
| 1492 | */ |
| 1493 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1494 | |
| 1495 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1496 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1497 | * |
| 1498 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1499 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1500 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1501 | * admins. |
| 1502 | * |
| 1503 | * @hide |
| 1504 | */ |
| 1505 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1506 | |
| 1507 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1508 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1509 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1510 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1511 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1512 | * |
| 1513 | * @hide |
| 1514 | */ |
| 1515 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1516 | |
| 1517 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1518 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1519 | * |
| 1520 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1521 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1522 | * |
| 1523 | * @hide |
| 1524 | */ |
| 1525 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1526 | |
| 1527 | /** |
| 1528 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1529 | * conditions. |
| 1530 | * |
| 1531 | * @hide |
| 1532 | */ |
| 1533 | @Retention(RetentionPolicy.SOURCE) |
| 1534 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1535 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1536 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1537 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1538 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1539 | public @interface ProvisioningPreCondition {} |
| 1540 | |
| 1541 | /** |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1542 | * Service action: Action for a service that device owner and profile owner can optionally |
| 1543 | * own. If a device owner or a profile owner has such a service, the system tries to keep |
| 1544 | * 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] | 1545 | * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN} |
| 1546 | * permission. |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1547 | */ |
| 1548 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
| 1549 | public static final String ACTION_DEVICE_ADMIN_SERVICE |
| 1550 | = "android.app.action.DEVICE_ADMIN_SERVICE"; |
| 1551 | |
| 1552 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1553 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1554 | * |
| 1555 | * @param admin The administrator component to check for. |
| 1556 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1557 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1558 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1559 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1560 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1561 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | /** |
| 1565 | * @see #isAdminActive(ComponentName) |
| 1566 | * @hide |
| 1567 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1568 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1569 | if (mService != null) { |
| 1570 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1571 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1572 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1573 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | return false; |
| 1577 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1578 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1579 | /** |
| 1580 | * Return true if the given administrator component is currently being removed |
| 1581 | * for the user. |
| 1582 | * @hide |
| 1583 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1584 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1585 | if (mService != null) { |
| 1586 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1587 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1588 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1589 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | return false; |
| 1593 | } |
| 1594 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1595 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1596 | * Return a list of all currently active device administrators' component |
| 1597 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1598 | * returned. |
| 1599 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1600 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1601 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1602 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * @see #getActiveAdmins() |
| 1607 | * @hide |
| 1608 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1609 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1610 | if (mService != null) { |
| 1611 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1612 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1613 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1614 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | return null; |
| 1618 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1619 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1620 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1621 | * Used by package administration code to determine if a package can be stopped |
| 1622 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1623 | * @hide |
| 1624 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1625 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 1626 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1627 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1628 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1629 | } |
| 1630 | |
| 1631 | /** |
| 1632 | * Used by package administration code to determine if a package can be stopped |
| 1633 | * or uninstalled. |
| 1634 | * @hide |
| 1635 | */ |
| 1636 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1637 | if (mService != null) { |
| 1638 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1639 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1640 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1641 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | return false; |
| 1645 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1646 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1647 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1648 | * Remove a current administration component. This can only be called |
| 1649 | * by the application that owns the administration component; if you |
| 1650 | * try to remove someone else's component, a security exception will be |
| 1651 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1652 | * |
| 1653 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1654 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1655 | * |
| 1656 | * @param admin The administration compononent to remove. |
| 1657 | * @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] | 1658 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1659 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1660 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1661 | if (mService != null) { |
| 1662 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1663 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1664 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1665 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1669 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1670 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1671 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1672 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1673 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1674 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1675 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1676 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1677 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1678 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1679 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1680 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1681 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1682 | if (mService != null) { |
| 1683 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1684 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1685 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1686 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | return false; |
| 1690 | } |
| 1691 | |
| 1692 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1693 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1694 | * |
| 1695 | * @hide |
| 1696 | */ |
| 1697 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1698 | if (mService != null) { |
| 1699 | try { |
| 1700 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1701 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1702 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1703 | } |
| 1704 | } |
| 1705 | return false; |
| 1706 | } |
| 1707 | |
| 1708 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1709 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1710 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1711 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1712 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1713 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1714 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1715 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1716 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1717 | * recognition technology. This implies technologies that can recognize the identity of |
| 1718 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1719 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1720 | */ |
| 1721 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1722 | |
| 1723 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1724 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1725 | * 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] | 1726 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1727 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1728 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1729 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1730 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1731 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1732 | * password containing at least numeric characters. Note that quality |
| 1733 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1734 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1735 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1736 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1737 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1738 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1739 | * password containing at least numeric characters with no repeating (4444) |
| 1740 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1741 | * constants are ordered so that higher values are more restrictive. |
| 1742 | */ |
| 1743 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1744 | |
| 1745 | /** |
| 1746 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1747 | * password containing at least alphabetic (or other symbol) characters. |
| 1748 | * Note that quality constants are ordered so that higher values are more |
| 1749 | * restrictive. |
| 1750 | */ |
| 1751 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1752 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1753 | /** |
| 1754 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1755 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1756 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1757 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1758 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1759 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1760 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1761 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1762 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1763 | * password containing at least a letter, a numerical digit and a special |
| 1764 | * symbol, by default. With this password quality, passwords can be |
| 1765 | * restricted to contain various sets of characters, like at least an |
| 1766 | * uppercase letter, etc. These are specified using various methods, |
| 1767 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1768 | * that quality constants are ordered so that higher values are more |
| 1769 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1770 | */ |
| 1771 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1772 | |
| 1773 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1774 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1775 | * modify password. In case this password quality is set, the password is |
| 1776 | * managed by a profile owner. The profile owner can set any password, |
| 1777 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1778 | * that quality constants are ordered so that higher values are more |
| 1779 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1780 | * the highest. |
| 1781 | * @hide |
| 1782 | */ |
| 1783 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1784 | |
| 1785 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1786 | * @hide |
| 1787 | * |
| 1788 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1789 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1790 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1791 | * used by authenticator to exempt their accounts from this: |
| 1792 | * |
| 1793 | * <ul> |
| 1794 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1795 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1796 | * <application> tag in the manifest. |
| 1797 | * |
| 1798 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1799 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1800 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1801 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1802 | * if any of the accounts have it. |
| 1803 | * </ul> |
| 1804 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1805 | @SystemApi |
| 1806 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1807 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1808 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1809 | |
| 1810 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1811 | @SystemApi |
| 1812 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1813 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1814 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1815 | |
| 1816 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1817 | * Called by an application that is administering the device to set the password restrictions it |
| 1818 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1819 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1820 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1821 | * 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] | 1822 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1823 | * <p> |
| 1824 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1825 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1826 | * considerations) is the one that is in effect. |
| 1827 | * <p> |
| 1828 | * The calling device admin must have requested |
| 1829 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1830 | * not, a security exception will be thrown. |
| 1831 | * <p> |
| 1832 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1833 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1834 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1835 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1836 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1837 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1838 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1839 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1840 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1841 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1842 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1843 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1844 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1845 | if (mService != null) { |
| 1846 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1847 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1848 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1849 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1850 | } |
| 1851 | } |
| 1852 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1853 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1854 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1855 | * 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] | 1856 | * 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] | 1857 | * a separate challenge are not taken into account. |
| 1858 | * |
| 1859 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1860 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1861 | * restrictions on the parent profile. |
| 1862 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1863 | * @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] | 1864 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1865 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1866 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1867 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1871 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1872 | if (mService != null) { |
| 1873 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1874 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1875 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1876 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1877 | } |
| 1878 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1879 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1880 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1881 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1882 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1883 | * Called by an application that is administering the device to set the minimum allowed password |
| 1884 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1885 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1886 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1887 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1888 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1889 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1890 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1891 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1892 | * {@link #setPasswordQuality}. |
| 1893 | * <p> |
| 1894 | * The calling device admin must have requested |
| 1895 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1896 | * not, a security exception will be thrown. |
| 1897 | * <p> |
| 1898 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1899 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1900 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1901 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1902 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1903 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1904 | * restriction. |
| 1905 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1906 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1907 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1908 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1909 | if (mService != null) { |
| 1910 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1911 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1912 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1913 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1917 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1918 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1919 | * 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] | 1920 | * 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] | 1921 | * a separate challenge are not taken into account. |
| 1922 | * |
| 1923 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1924 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1925 | * restrictions on the parent profile. |
| 1926 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1927 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1928 | * @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] | 1929 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1930 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1931 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1932 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1936 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1937 | if (mService != null) { |
| 1938 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1939 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1940 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1941 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | return 0; |
| 1945 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1946 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1947 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1948 | * Called by an application that is administering the device to set the minimum number of upper |
| 1949 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1950 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1951 | * current password will remain until the user has set a new one, so the change does not take |
| 1952 | * place immediately. To prompt the user for a new password, use |
| 1953 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1954 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1955 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1956 | * <p> |
| 1957 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1958 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1959 | * not, a security exception will be thrown. |
| 1960 | * <p> |
| 1961 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1962 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1963 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1964 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1965 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1966 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1967 | * A value of 0 means there is no restriction. |
| 1968 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1969 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1970 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1971 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1972 | if (mService != null) { |
| 1973 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1974 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1975 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1976 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1982 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1983 | * 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] | 1984 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1985 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1986 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1987 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1988 | * and only applies when the password quality is |
| 1989 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1990 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1991 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1992 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1993 | * restrictions on the parent profile. |
| 1994 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1995 | * @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] | 1996 | * aggregate all admins. |
| 1997 | * @return The minimum number of upper case letters required in the |
| 1998 | * password. |
| 1999 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2000 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2001 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2005 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2006 | if (mService != null) { |
| 2007 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2008 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2009 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2010 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | return 0; |
| 2014 | } |
| 2015 | |
| 2016 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2017 | * Called by an application that is administering the device to set the minimum number of lower |
| 2018 | * case letters required in the password. After setting this, the user will not be able to enter |
| 2019 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 2020 | * current password will remain until the user has set a new one, so the change does not take |
| 2021 | * place immediately. To prompt the user for a new password, use |
| 2022 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2023 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2024 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2025 | * <p> |
| 2026 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2027 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2028 | * not, a security exception will be thrown. |
| 2029 | * <p> |
| 2030 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2031 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2032 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2033 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2034 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2035 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2036 | * A value of 0 means there is no restriction. |
| 2037 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2038 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2039 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2040 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2041 | if (mService != null) { |
| 2042 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2043 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2044 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2045 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2046 | } |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2051 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2052 | * 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] | 2053 | * and its participating profiles. Restrictions on profiles that have |
| 2054 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2055 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2056 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2057 | * and only applies when the password quality is |
| 2058 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2059 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2060 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2061 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2062 | * restrictions on the parent profile. |
| 2063 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2064 | * @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] | 2065 | * aggregate all admins. |
| 2066 | * @return The minimum number of lower case letters required in the |
| 2067 | * password. |
| 2068 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2069 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2070 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2074 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2075 | if (mService != null) { |
| 2076 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2077 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2078 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2079 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | return 0; |
| 2083 | } |
| 2084 | |
| 2085 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2086 | * Called by an application that is administering the device to set the minimum number of |
| 2087 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2088 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2089 | * password will remain until the user has set a new one, so the change does not take place |
| 2090 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2091 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2092 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2093 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2094 | * <p> |
| 2095 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2096 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2097 | * not, a security exception will be thrown. |
| 2098 | * <p> |
| 2099 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2100 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2101 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2102 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2103 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2104 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2105 | * 0 means there is no restriction. |
| 2106 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2107 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2108 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2109 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2110 | if (mService != null) { |
| 2111 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2112 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2113 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2114 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2120 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2121 | * 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] | 2122 | * and its participating profiles. Restrictions on profiles that have |
| 2123 | * a separate challenge are not taken into account. |
| 2124 | * This is the same value as set by |
| 2125 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2126 | * and only applies when the password quality is |
| 2127 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2128 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2129 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2130 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2131 | * restrictions on the parent profile. |
| 2132 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2133 | * @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] | 2134 | * aggregate all admins. |
| 2135 | * @return The minimum number of letters required in the password. |
| 2136 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2137 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2138 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2142 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2143 | if (mService != null) { |
| 2144 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2145 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2146 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2147 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2148 | } |
| 2149 | } |
| 2150 | return 0; |
| 2151 | } |
| 2152 | |
| 2153 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2154 | * Called by an application that is administering the device to set the minimum number of |
| 2155 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2156 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2157 | * current password will remain until the user has set a new one, so the change does not take |
| 2158 | * place immediately. To prompt the user for a new password, use |
| 2159 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2160 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2161 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2162 | * <p> |
| 2163 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2164 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2165 | * not, a security exception will be thrown. |
| 2166 | * <p> |
| 2167 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2168 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2169 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2170 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2171 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2172 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2173 | * value of 0 means there is no restriction. |
| 2174 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2175 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2176 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2177 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2178 | if (mService != null) { |
| 2179 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2180 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2181 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2182 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | /** |
| 2188 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2189 | * 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] | 2190 | * and its participating profiles. Restrictions on profiles that have |
| 2191 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2192 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2193 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2194 | * and only applies when the password quality is |
| 2195 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2196 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2197 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2198 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2199 | * restrictions on the parent profile. |
| 2200 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2201 | * @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] | 2202 | * aggregate all admins. |
| 2203 | * @return The minimum number of numerical digits required in the password. |
| 2204 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2205 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2206 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2210 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2211 | if (mService != null) { |
| 2212 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2213 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2214 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2215 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2216 | } |
| 2217 | } |
| 2218 | return 0; |
| 2219 | } |
| 2220 | |
| 2221 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2222 | * Called by an application that is administering the device to set the minimum number of |
| 2223 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2224 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2225 | * password will remain until the user has set a new one, so the change does not take place |
| 2226 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2227 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2228 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2229 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2230 | * <p> |
| 2231 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2232 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2233 | * not, a security exception will be thrown. |
| 2234 | * <p> |
| 2235 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2236 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2237 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2238 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2239 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2240 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2241 | * 0 means there is no restriction. |
| 2242 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2243 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2244 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2245 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2246 | if (mService != null) { |
| 2247 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2248 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2249 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2250 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2251 | } |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2256 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2257 | * 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] | 2258 | * and its participating profiles. Restrictions on profiles that have |
| 2259 | * a separate challenge are not taken into account. This is the same value as |
| 2260 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2261 | * and only applies when the password quality is |
| 2262 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2263 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2264 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2265 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2266 | * restrictions on the parent profile. |
| 2267 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2268 | * @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] | 2269 | * aggregate all admins. |
| 2270 | * @return The minimum number of symbols required in the password. |
| 2271 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2272 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2273 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2277 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2278 | if (mService != null) { |
| 2279 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2280 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2281 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2282 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2283 | } |
| 2284 | } |
| 2285 | return 0; |
| 2286 | } |
| 2287 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2288 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2289 | * Called by an application that is administering the device to set the minimum number of |
| 2290 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2291 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2292 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2293 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2294 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2295 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2296 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2297 | * <p> |
| 2298 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2299 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2300 | * not, a security exception will be thrown. |
| 2301 | * <p> |
| 2302 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2303 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2304 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2305 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2306 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2307 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2308 | * 0 means there is no restriction. |
| 2309 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2310 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2311 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2312 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2313 | if (mService != null) { |
| 2314 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2315 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2316 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2317 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2323 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2324 | * 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] | 2325 | * and its participating profiles. Restrictions on profiles that have |
| 2326 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2327 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2328 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2329 | * and only applies when the password quality is |
| 2330 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2331 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2332 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2333 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2334 | * restrictions on the parent profile. |
| 2335 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2336 | * @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] | 2337 | * aggregate all admins. |
| 2338 | * @return The minimum number of letters required in the password. |
| 2339 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2340 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2341 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2345 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2346 | if (mService != null) { |
| 2347 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2348 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2349 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2350 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | return 0; |
| 2354 | } |
| 2355 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2356 | /** |
| 2357 | * Called by an application that is administering the device to set the length of the password |
| 2358 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2359 | * same as any password in the history. Note that the current password will remain until the |
| 2360 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2361 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2362 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2363 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2364 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2365 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2366 | * <p> |
| 2367 | * The calling device admin must have requested |
| 2368 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2369 | * not, a security exception will be thrown. |
| 2370 | * <p> |
| 2371 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2372 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2373 | * profile. |
| 2374 | * |
| 2375 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2376 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2377 | * restriction. |
| 2378 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2379 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2380 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2381 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2382 | if (mService != null) { |
| 2383 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2384 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2385 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2386 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2392 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2393 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2394 | * device password (for all admins). |
| 2395 | * <p> |
| 2396 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2397 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2398 | * 432000000 ms for timeout. |
| 2399 | * <p> |
| 2400 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2401 | * <p> |
| 2402 | * The calling device admin must have requested |
| 2403 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2404 | * not, a security exception will be thrown. |
| 2405 | * <p> |
| 2406 | * Note that setting the password will automatically reset the expiration time for all active |
| 2407 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2408 | * <p> |
| 2409 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2410 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2411 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2412 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2413 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2414 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2415 | * there is no restriction (unlimited). |
| 2416 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2417 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2418 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2419 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2420 | if (mService != null) { |
| 2421 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2422 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2423 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2424 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2425 | } |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2430 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2431 | * recurring expiration timeout provided in the call to |
| 2432 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2433 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2434 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2435 | * |
| 2436 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2437 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2438 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2439 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2440 | * @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] | 2441 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2442 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2443 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2444 | if (mService != null) { |
| 2445 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2446 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2447 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2448 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2449 | } |
| 2450 | } |
| 2451 | return 0; |
| 2452 | } |
| 2453 | |
| 2454 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2455 | * 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] | 2456 | * 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] | 2457 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2458 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2459 | * |
| 2460 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2461 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2462 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2463 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2464 | * @param admin The name of the admin component to check, or {@code null} to aggregate all admins. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2465 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2466 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2467 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2468 | if (mService != null) { |
| 2469 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2470 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2471 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2472 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |
| 2478 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2479 | * 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] | 2480 | * 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] | 2481 | * have a separate challenge are not taken into account. |
| 2482 | * |
| 2483 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2484 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2485 | * restrictions on the parent profile. |
| 2486 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2487 | * @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] | 2488 | * all admins. |
| 2489 | * @return The length of the password history |
| 2490 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2491 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2492 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2496 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2497 | if (mService != null) { |
| 2498 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2499 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2500 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2501 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2502 | } |
| 2503 | } |
| 2504 | return 0; |
| 2505 | } |
| 2506 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2507 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2508 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2509 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2510 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2511 | * @return Returns the maximum length that the user can enter. |
| 2512 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2513 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2514 | // Kind-of arbitrary. |
| 2515 | return 16; |
| 2516 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2517 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2518 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2519 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2520 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2521 | * 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] | 2522 | * 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] | 2523 | * <p> |
| 2524 | * The calling device admin must have requested |
| 2525 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2526 | * not, a security exception will be thrown. |
| 2527 | * <p> |
| 2528 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2529 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2530 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2531 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2532 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2533 | * @throws SecurityException if the calling application does not own an active administrator |
| 2534 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2535 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2536 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2537 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2538 | if (mService != null) { |
| 2539 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2540 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2541 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2542 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2543 | } |
| 2544 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2545 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2546 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2547 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2548 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2549 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2550 | * 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] | 2551 | * requested by the admins of the parent user and its profiles. |
| 2552 | * |
| 2553 | * @param userHandle the userId of the profile to check the password for. |
| 2554 | * @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] | 2555 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2556 | * @hide |
| 2557 | */ |
| 2558 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2559 | if (mService != null) { |
| 2560 | try { |
| 2561 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2562 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2563 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2564 | } |
| 2565 | } |
| 2566 | return false; |
| 2567 | } |
| 2568 | |
| 2569 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2570 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2571 | * successful password entry. |
| 2572 | * <p> |
| 2573 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2574 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2575 | * password attemts for the parent user. |
| 2576 | * <p> |
| 2577 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2578 | * 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] | 2579 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2580 | * @return The number of times user has entered an incorrect password since the last correct |
| 2581 | * password entry. |
| 2582 | * @throws SecurityException if the calling application does not own an active administrator |
| 2583 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2584 | */ |
| 2585 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2586 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2587 | } |
| 2588 | |
| 2589 | /** |
| 2590 | * Retrieve the number of times the given user has failed at entering a |
| 2591 | * password since that last successful password entry. |
| 2592 | * |
| 2593 | * <p>The calling device admin must have requested |
| 2594 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2595 | * not and it is not the system uid, a security exception will be thrown. |
| 2596 | * |
| 2597 | * @hide |
| 2598 | */ |
| 2599 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2600 | if (mService != null) { |
| 2601 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2602 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2603 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2604 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2605 | } |
| 2606 | } |
| 2607 | return -1; |
| 2608 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2609 | |
| 2610 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2611 | * 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] | 2612 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2613 | * @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] | 2614 | * @hide |
| 2615 | */ |
| 2616 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2617 | if (mService != null) { |
| 2618 | try { |
| 2619 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2620 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2621 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | return false; |
| 2625 | } |
| 2626 | |
| 2627 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2628 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2629 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2630 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2631 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2632 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2633 | * <p> |
| 2634 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2635 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2636 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2637 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2638 | * immediately, and your callback will not be invoked. |
| 2639 | * <p> |
| 2640 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2641 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2642 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2643 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2644 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2645 | * @param num The number of failed password attempts at which point the device or profile will |
| 2646 | * be wiped. |
| 2647 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2648 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2649 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2650 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2651 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2652 | if (mService != null) { |
| 2653 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2654 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2655 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2656 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2660 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2661 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2662 | * 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] | 2663 | * 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] | 2664 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2665 | * not taken into account. |
| 2666 | * |
| 2667 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2668 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2669 | * the value for the parent profile. |
| 2670 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2671 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2672 | * all admins. |
| 2673 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2674 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2675 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2679 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2680 | if (mService != null) { |
| 2681 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2682 | return mService.getMaximumFailedPasswordsForWipe( |
| 2683 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2684 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2685 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | return 0; |
| 2689 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2690 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2691 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2692 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2693 | * for the given user. So for primary user, it might return the primary or |
| 2694 | * a managed profile. For a secondary user, it would be the same as the |
| 2695 | * user passed in. |
| 2696 | * @hide Used only by Keyguard |
| 2697 | */ |
| 2698 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2699 | if (mService != null) { |
| 2700 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2701 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2702 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2703 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2704 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2705 | } |
| 2706 | } |
| 2707 | return UserHandle.USER_NULL; |
| 2708 | } |
| 2709 | |
| 2710 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2711 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2712 | * the password again until the user has entered it. |
| 2713 | */ |
| 2714 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2715 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2716 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2717 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2718 | * If the flag is set, the device can be booted without asking for user password. |
| 2719 | * The absence of this flag does not change the current boot requirements. This flag |
| 2720 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2721 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2722 | * device to factory defaults. |
| 2723 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2724 | 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] | 2725 | |
| 2726 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2727 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2728 | * individual accounts) on the user. This takes effect immediately. |
| 2729 | * <p> |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2730 | * <em>For device owner and profile owners targeting SDK level |
| 2731 | * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will |
| 2732 | * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken} |
| 2733 | * instead. </em> |
| 2734 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2735 | * <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] | 2736 | * device admins that are not device owner and not profile owner. |
| 2737 | * 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] | 2738 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2739 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2740 | * <p> |
| 2741 | * The given password must be sufficient for the current password quality and length constraints |
| 2742 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2743 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2744 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2745 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2746 | * case the currently active quality will be increased to match. |
| 2747 | * <p> |
| 2748 | * 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] | 2749 | * current password constraints allow it. <em>Note: This will not work in |
| 2750 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2751 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2752 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2753 | * <p> |
| 2754 | * The calling device admin must have requested |
| 2755 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2756 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2757 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2758 | * @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] | 2759 | * @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] | 2760 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2761 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2762 | * current constraints or if the user has not been decrypted yet. |
| 2763 | * @throws SecurityException if the calling application does not own an active administrator |
| 2764 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2765 | * @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] | 2766 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2767 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2768 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2769 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2770 | if (mService != null) { |
| 2771 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2772 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2773 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2774 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | return false; |
| 2778 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2779 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2780 | /** |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2781 | * Called by a profile or device owner to provision a token which can later be used to reset the |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2782 | * device lockscreen password (if called by device owner), or managed profile challenge (if |
| 2783 | * called by profile owner), via {@link #resetPasswordWithToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2784 | * <p> |
| 2785 | * If the user currently has a lockscreen password, the provisioned token will not be |
| 2786 | * immediately usable; it only becomes active after the user performs a confirm credential |
| 2787 | * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 2788 | * If the user has no lockscreen password, the token is activated immediately. In all cases, |
| 2789 | * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}. |
| 2790 | * For security reasons, un-activated tokens are only stored in memory and will be lost once |
| 2791 | * the device reboots. In this case a new token needs to be provisioned again. |
| 2792 | * <p> |
| 2793 | * Once provisioned and activated, the token will remain effective even if the user changes |
| 2794 | * or clears the lockscreen password. |
| 2795 | * <p> |
| 2796 | * <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] | 2797 | * credentials. In particular, NEVER store this token on device in plaintext. Do not store |
| 2798 | * the plaintext token in device-encrypted storage if it will be needed to reset password on |
| 2799 | * file-based encryption devices before user unlocks. Consider carefully how any password token |
| 2800 | * will be stored on your server and who will need access to them. Tokens may be the subject of |
| 2801 | * legal access requests. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2802 | * </em> |
| 2803 | * |
| 2804 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2805 | * @param token a secure token a least 32-byte long, which must be generated by a |
| 2806 | * cryptographically strong random number generator. |
| 2807 | * @return true if the operation is successful, false otherwise. |
| 2808 | * @throws IllegalArgumentException if the supplied token is invalid. |
| 2809 | * @throws SecurityException |
| 2810 | */ |
| 2811 | public boolean setResetPasswordToken(ComponentName admin, byte[] token) { |
| 2812 | throwIfParentInstance("setResetPasswordToken"); |
| 2813 | if (mService != null) { |
| 2814 | try { |
| 2815 | return mService.setResetPasswordToken(admin, token); |
| 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 revoke the current password reset token. |
| 2825 | * |
| 2826 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2827 | * @return true if the operation is successful, false otherwise. |
| 2828 | */ |
| 2829 | public boolean clearResetPasswordToken(ComponentName admin) { |
| 2830 | throwIfParentInstance("clearResetPasswordToken"); |
| 2831 | if (mService != null) { |
| 2832 | try { |
| 2833 | return mService.clearResetPasswordToken(admin); |
| 2834 | } catch (RemoteException e) { |
| 2835 | throw e.rethrowFromSystemServer(); |
| 2836 | } |
| 2837 | } |
| 2838 | return false; |
| 2839 | } |
| 2840 | |
| 2841 | /** |
| 2842 | * Called by a profile or device owner to check if the current reset password token is active. |
| 2843 | * |
| 2844 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2845 | * @return true if the token is active, false otherwise. |
| 2846 | * @throws IllegalStateException if no token has been set. |
| 2847 | */ |
| 2848 | public boolean isResetPasswordTokenActive(ComponentName admin) { |
| 2849 | throwIfParentInstance("isResetPasswordTokenActive"); |
| 2850 | if (mService != null) { |
| 2851 | try { |
| 2852 | return mService.isResetPasswordTokenActive(admin); |
| 2853 | } catch (RemoteException e) { |
| 2854 | throw e.rethrowFromSystemServer(); |
| 2855 | } |
| 2856 | } |
| 2857 | return false; |
| 2858 | } |
| 2859 | |
| 2860 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2861 | * Called by device or profile owner to force set a new device unlock password or a managed |
| 2862 | * profile challenge on current user. This takes effect immediately. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2863 | * <p> |
| 2864 | * Unlike {@link #resetPassword}, this API can change the password even before the user or |
| 2865 | * device is unlocked or decrypted. The supplied token must have been previously provisioned via |
| 2866 | * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}. |
| 2867 | * <p> |
| 2868 | * The given password must be sufficient for the current password quality and length constraints |
| 2869 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2870 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2871 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2872 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2873 | * case the currently active quality will be increased to match. |
| 2874 | * <p> |
| 2875 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
| 2876 | * current password constraints allow it. |
| 2877 | * |
| 2878 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2879 | * @param password The new password for the user. Null or empty clears the password. |
| 2880 | * @param token the password reset token previously provisioned by #setResetPasswordToken. |
| 2881 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
| 2882 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2883 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2884 | * current constraints. |
| 2885 | * @throws SecurityException if the calling application does not own an active administrator |
| 2886 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
| 2887 | * @throws IllegalStateException if the provided token is not valid. |
| 2888 | * @throws IllegalArgumentException if the password does not meet system requirements. |
| 2889 | */ |
| 2890 | public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password, |
| 2891 | byte[] token, int flags) { |
| 2892 | throwIfParentInstance("resetPassword"); |
| 2893 | if (mService != null) { |
| 2894 | try { |
| 2895 | return mService.resetPasswordWithToken(admin, password, token, flags); |
| 2896 | } catch (RemoteException e) { |
| 2897 | throw e.rethrowFromSystemServer(); |
| 2898 | } |
| 2899 | } |
| 2900 | return false; |
| 2901 | } |
| 2902 | |
| 2903 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2904 | * Called by an application that is administering the device to set the maximum time for user |
| 2905 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2906 | * effect immediately. |
| 2907 | * <p> |
| 2908 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2909 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2910 | * <p> |
| 2911 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2912 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2913 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2914 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2915 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2916 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2917 | * is no restriction. |
| 2918 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2919 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2920 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2921 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2922 | if (mService != null) { |
| 2923 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2924 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2925 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2926 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2930 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2931 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2932 | * 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] | 2933 | * 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] | 2934 | * a separate challenge are not taken into account. |
| 2935 | * |
| 2936 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2937 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2938 | * restrictions on the parent profile. |
| 2939 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2940 | * @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] | 2941 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2942 | * @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] | 2943 | * 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] | 2944 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2945 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2946 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2950 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2951 | if (mService != null) { |
| 2952 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2953 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2954 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2955 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2956 | } |
| 2957 | } |
| 2958 | return 0; |
| 2959 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2960 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2961 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2962 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2963 | * do not have a separate timeout to lock for work challenge only. |
| 2964 | * |
| 2965 | * @hide |
| 2966 | */ |
| 2967 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2968 | if (mService != null) { |
| 2969 | try { |
| 2970 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2971 | } catch (RemoteException e) { |
| 2972 | throw e.rethrowFromSystemServer(); |
| 2973 | } |
| 2974 | } |
| 2975 | return 0; |
| 2976 | } |
| 2977 | |
| 2978 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2979 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2980 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2981 | * authentication method like password, pin or pattern. |
| 2982 | * |
| 2983 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2984 | * specified timeout each time it has been successfully used. |
| 2985 | * |
| 2986 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2987 | * |
| 2988 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2989 | * |
| 2990 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2991 | * a {@link SecurityException} will be thrown. |
| 2992 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2993 | * <p>The calling device admin can verify the value it has set by calling |
| 2994 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2995 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2996 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2997 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2998 | * profile. |
| 2999 | * |
| 3000 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3001 | * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock |
| 3002 | * with strong authentication method. A value of 0 means the admin is not participating |
| 3003 | * in controlling the timeout. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 3004 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 3005 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 3006 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 3007 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3008 | * |
| 3009 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3010 | */ |
| 3011 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 3012 | long timeoutMs) { |
| 3013 | if (mService != null) { |
| 3014 | try { |
| 3015 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 3016 | } catch (RemoteException e) { |
| 3017 | throw e.rethrowFromSystemServer(); |
| 3018 | } |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | /** |
| 3023 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 3024 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 3025 | * After the returned timeout the user is required to use strong authentication method. |
| 3026 | * |
| 3027 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3028 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3029 | * restrictions on the parent profile. |
| 3030 | * |
| 3031 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 3032 | * accross all participating admins. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3033 | * @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] | 3034 | */ |
| 3035 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 3036 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 3037 | } |
| 3038 | |
| 3039 | /** @hide per-user version */ |
| 3040 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 3041 | if (mService != null) { |
| 3042 | try { |
| 3043 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 3044 | } catch (RemoteException e) { |
| 3045 | throw e.rethrowFromSystemServer(); |
| 3046 | } |
| 3047 | } |
| 3048 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 3049 | } |
| 3050 | |
| 3051 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3052 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 3053 | * keyring. The user's credential will need to be entered again in order to derive the |
| 3054 | * credential encryption key that will be stored back in the keyring for future use. |
| 3055 | * <p> |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3056 | * This flag can only be used by a profile owner when locking a managed profile when |
| 3057 | * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3058 | * <p> |
| 3059 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 3060 | * until they are next run to perform further actions. |
| 3061 | */ |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3062 | public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1; |
| 3063 | |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3064 | /** @hide */ |
| 3065 | @Retention(RetentionPolicy.SOURCE) |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3066 | @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}) |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3067 | public @interface LockNowFlag {} |
| 3068 | |
| 3069 | /** |
| 3070 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3071 | * this call. |
| 3072 | * <p> |
| 3073 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3074 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3075 | * <p> |
| 3076 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3077 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 3078 | * <p> |
| 3079 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 3080 | * |
| 3081 | * @throws SecurityException if the calling application does not own an active administrator |
| 3082 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3083 | */ |
| 3084 | public void lockNow() { |
| 3085 | lockNow(0); |
| 3086 | } |
| 3087 | |
| 3088 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3089 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3090 | * this call. |
| 3091 | * <p> |
| 3092 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3093 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3094 | * <p> |
| 3095 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3096 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3097 | * |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3098 | * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3099 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3100 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3101 | * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application |
| 3102 | * that is not a profile |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3103 | * owner of a managed profile. |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3104 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is |
| 3105 | * passed when locking the parent profile. |
| 3106 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} |
| 3107 | * flag is passed when {@link #getStorageEncryptionStatus} does not return |
| 3108 | * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3109 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3110 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3111 | if (mService != null) { |
| 3112 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3113 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3114 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3115 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3119 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3120 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3121 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3122 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3123 | */ |
| 3124 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 3125 | |
| 3126 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3127 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 3128 | * data. |
| 3129 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 3130 | * <p>This flag may only be set by device owner admins; if it is set by |
| 3131 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3132 | */ |
| 3133 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 3134 | |
| 3135 | /** |
yinxu | f4f9cec | 2017-06-19 10:28:19 -0700 | [diff] [blame] | 3136 | * Flag for {@link #wipeData(int)}: also erase the device's eUICC data. |
| 3137 | * |
| 3138 | * TODO(b/35851809): make this public. |
| 3139 | * @hide |
| 3140 | */ |
| 3141 | public static final int WIPE_EUICC = 0x0004; |
| 3142 | |
| 3143 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 3144 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3145 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 3146 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 3147 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3148 | * <p> |
| 3149 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3150 | * 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] | 3151 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3152 | * @param flags Bit mask of additional options: currently supported flags are |
| 3153 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3154 | * @throws SecurityException if the calling application does not own an active administrator |
| 3155 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3156 | */ |
| 3157 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3158 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3159 | if (mService != null) { |
| 3160 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3161 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3162 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3163 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3167 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3168 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3169 | * Called by an application that is administering the device to set the |
| 3170 | * global proxy and exclusion list. |
| 3171 | * <p> |
| 3172 | * The calling device admin must have requested |
| 3173 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3174 | * this method; if it has not, a security exception will be thrown. |
| 3175 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3176 | * 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] | 3177 | * 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] | 3178 | * be returned. |
| 3179 | * The method can be called repeatedly by the device admin alrady setting the |
| 3180 | * proxy to update the proxy and exclusion list. |
| 3181 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3182 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3183 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3184 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3185 | * @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] | 3186 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3187 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3188 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3189 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3190 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3191 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3192 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3193 | if (proxySpec == null) { |
| 3194 | throw new NullPointerException(); |
| 3195 | } |
| 3196 | if (mService != null) { |
| 3197 | try { |
| 3198 | String hostSpec; |
| 3199 | String exclSpec; |
| 3200 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3201 | hostSpec = null; |
| 3202 | exclSpec = null; |
| 3203 | } else { |
| 3204 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3205 | throw new IllegalArgumentException(); |
| 3206 | } |
| 3207 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3208 | String hostName = sa.getHostName(); |
| 3209 | int port = sa.getPort(); |
| 3210 | StringBuilder hostBuilder = new StringBuilder(); |
| 3211 | hostSpec = hostBuilder.append(hostName) |
| 3212 | .append(":").append(Integer.toString(port)).toString(); |
| 3213 | if (exclusionList == null) { |
| 3214 | exclSpec = ""; |
| 3215 | } else { |
| 3216 | StringBuilder listBuilder = new StringBuilder(); |
| 3217 | boolean firstDomain = true; |
| 3218 | for (String exclDomain : exclusionList) { |
| 3219 | if (!firstDomain) { |
| 3220 | listBuilder = listBuilder.append(","); |
| 3221 | } else { |
| 3222 | firstDomain = false; |
| 3223 | } |
| 3224 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3225 | } |
| 3226 | exclSpec = listBuilder.toString(); |
| 3227 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3228 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3229 | != android.net.Proxy.PROXY_VALID) |
| 3230 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3231 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3232 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3233 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3234 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3235 | } |
| 3236 | } |
| 3237 | return null; |
| 3238 | } |
| 3239 | |
| 3240 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3241 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3242 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3243 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3244 | * proxy is not accessible, you may break HTTP using this. |
| 3245 | * <p> |
| 3246 | * This method requires the caller to be the device owner. |
| 3247 | * <p> |
| 3248 | * 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] | 3249 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3250 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3251 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3252 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3253 | * {@code null} value will clear the global HTTP proxy. |
| 3254 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3255 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3256 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3257 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3258 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3259 | if (mService != null) { |
| 3260 | try { |
| 3261 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3262 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3263 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3264 | } |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3269 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3270 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3271 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3272 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3273 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3274 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3275 | if (mService != null) { |
| 3276 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3277 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3278 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3279 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | return null; |
| 3283 | } |
| 3284 | |
| 3285 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3286 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3287 | * indicating that encryption is not supported. |
| 3288 | */ |
| 3289 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3290 | |
| 3291 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3292 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3293 | * indicating that encryption is supported, but is not currently active. |
| 3294 | */ |
| 3295 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3296 | |
| 3297 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3298 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3299 | * indicating that encryption is not currently active, but is currently |
| 3300 | * being activated. This is only reported by devices that support |
| 3301 | * encryption of data and only when the storage is currently |
| 3302 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3303 | * to become encrypted will never return this value. |
| 3304 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3305 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3306 | |
| 3307 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3308 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3309 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3310 | * <p> |
| 3311 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3312 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3313 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3314 | |
| 3315 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3316 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3317 | * indicating that encryption is active, but an encryption key has not |
| 3318 | * been set by the user. |
| 3319 | */ |
| 3320 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3321 | |
| 3322 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3323 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3324 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3325 | * <p> |
| 3326 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3327 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3328 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3329 | */ |
| 3330 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3331 | |
| 3332 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3333 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3334 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3335 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3336 | * to check encryption status. However, on some devices this activity may never return, as |
| 3337 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3338 | */ |
| 3339 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3340 | public static final String ACTION_START_ENCRYPTION |
| 3341 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3342 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3343 | * Widgets are enabled in keyguard |
| 3344 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3345 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3346 | |
| 3347 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3348 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3349 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3350 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3351 | |
| 3352 | /** |
| 3353 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3354 | */ |
| 3355 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3356 | |
| 3357 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3358 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3359 | */ |
| 3360 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3361 | |
| 3362 | /** |
| 3363 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3364 | */ |
| 3365 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3366 | |
| 3367 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3368 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3369 | * (e.g. PIN/Pattern/Password). |
| 3370 | */ |
| 3371 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3372 | |
| 3373 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3374 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3375 | */ |
| 3376 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3377 | |
| 3378 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3379 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3380 | */ |
| 3381 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3382 | |
| 3383 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3384 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3385 | */ |
| 3386 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3387 | |
| 3388 | /** |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3389 | * Keyguard features that when set on a managed profile that doesn't have its own challenge will |
| 3390 | * affect the profile's parent user. These can also be set on the managed profile's parent |
| 3391 | * {@link DevicePolicyManager} instance. |
| 3392 | * |
| 3393 | * @hide |
| 3394 | */ |
| 3395 | public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER = |
| 3396 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS |
| 3397 | | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT; |
| 3398 | |
| 3399 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3400 | * Called by an application that is administering the device to request that the storage system |
| 3401 | * be encrypted. |
| 3402 | * <p> |
| 3403 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3404 | * supported setting will always be used. If any device administrator requests device |
| 3405 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3406 | * 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] | 3407 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3408 | * <p> |
| 3409 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3410 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3411 | * control the encryption of any other storage areas. There is one exception: If |
| 3412 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3413 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3414 | * written to disk within the encrypted storage area. |
| 3415 | * <p> |
| 3416 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3417 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3418 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3419 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3420 | * |
| 3421 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3422 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3423 | * @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] | 3424 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3425 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3426 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3427 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3428 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3429 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3430 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3431 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3432 | if (mService != null) { |
| 3433 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3434 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3435 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3436 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3437 | } |
| 3438 | } |
| 3439 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3440 | } |
| 3441 | |
| 3442 | /** |
| 3443 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3444 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3445 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3446 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3447 | * this will return the requested encryption setting as an aggregate of all active |
| 3448 | * administrators. |
| 3449 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3450 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3451 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3452 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3453 | if (mService != null) { |
| 3454 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3455 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3456 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3457 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3458 | } |
| 3459 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3460 | return false; |
| 3461 | } |
| 3462 | |
| 3463 | /** |
| 3464 | * Called by an application that is administering the device to |
| 3465 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3466 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3467 | * Depending on the returned status code, the caller may proceed in different |
| 3468 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3469 | * storage system does not support encryption. If the |
| 3470 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3471 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3472 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3473 | * 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] | 3474 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3475 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3476 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3477 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3478 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3479 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3480 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3481 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3482 | */ |
| 3483 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3484 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3485 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | /** @hide per-user version */ |
| 3489 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3490 | if (mService != null) { |
| 3491 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3492 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3493 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3494 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3495 | } |
| 3496 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3497 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3498 | } |
| 3499 | |
| 3500 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3501 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3502 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3503 | * keep the certificate on the device. |
| 3504 | * |
| 3505 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3506 | * this certificate. |
| 3507 | * |
| 3508 | * @hide |
| 3509 | */ |
| 3510 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3511 | if (mService != null) { |
| 3512 | try { |
| 3513 | return mService.approveCaCert(alias, userHandle, approval); |
| 3514 | } catch (RemoteException e) { |
| 3515 | throw e.rethrowFromSystemServer(); |
| 3516 | } |
| 3517 | } |
| 3518 | return false; |
| 3519 | } |
| 3520 | |
| 3521 | /** |
| 3522 | * Check whether a CA certificate has been approved by the device user. |
| 3523 | * |
| 3524 | * @hide |
| 3525 | */ |
| 3526 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3527 | if (mService != null) { |
| 3528 | try { |
| 3529 | return mService.isCaCertApproved(alias, userHandle); |
| 3530 | } catch (RemoteException e) { |
| 3531 | throw e.rethrowFromSystemServer(); |
| 3532 | } |
| 3533 | } |
| 3534 | return false; |
| 3535 | } |
| 3536 | |
| 3537 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3538 | * Installs the given certificate as a user CA. |
| 3539 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3540 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3541 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3542 | * security exception will be thrown. |
| 3543 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3544 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3545 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3546 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3547 | * |
| 3548 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3549 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3550 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3551 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3552 | * @see #setDelegatedScopes |
| 3553 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3554 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3555 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3556 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3557 | if (mService != null) { |
| 3558 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3559 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3560 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3561 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | return false; |
| 3565 | } |
| 3566 | |
| 3567 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3568 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3569 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3570 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3571 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3572 | * security exception will be thrown. |
| 3573 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3574 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3575 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3576 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3577 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3578 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3579 | * @see #setDelegatedScopes |
| 3580 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3581 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3582 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3583 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3584 | if (mService != null) { |
| 3585 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3586 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3587 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3588 | } catch (CertificateException e) { |
| 3589 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3590 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3591 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3592 | } |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3597 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3598 | * If a user has installed any certificates by other means than device policy these will be |
| 3599 | * included too. |
| 3600 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3601 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3602 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3603 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3604 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3605 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3606 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3607 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3608 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3609 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3610 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3611 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3612 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3613 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3614 | for (String alias : certStore.userAliases()) { |
| 3615 | try { |
| 3616 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3617 | } catch (CertificateException ce) { |
| 3618 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3619 | } |
| 3620 | } |
| 3621 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3622 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3623 | } |
| 3624 | } |
| 3625 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3629 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3630 | * means other than device policy will also be removed, except for system CA certificates. |
| 3631 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3632 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3633 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3634 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3635 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3636 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3637 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3638 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3639 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3640 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3641 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3642 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3643 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3644 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3645 | } |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Returns whether this certificate is installed as a trusted CA. |
| 3651 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3652 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3653 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3654 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3655 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3656 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3657 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3658 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3659 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3660 | if (mService != null) { |
| 3661 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3662 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3663 | return getCaCertAlias(certBuffer) != null; |
| 3664 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3665 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3666 | } catch (CertificateException ce) { |
| 3667 | Log.w(TAG, "Could not parse certificate", ce); |
| 3668 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3669 | } |
| 3670 | return false; |
| 3671 | } |
| 3672 | |
| 3673 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3674 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3675 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3676 | * the certificate and use the private key, given direct user approval. |
| 3677 | * |
| 3678 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3679 | * direct user approval. This is for security - should a certificate installer become |
| 3680 | * compromised, certificates it had already installed will be protected. |
| 3681 | * |
| 3682 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3683 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3684 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3686 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3687 | * @param privKey The private key to install. |
| 3688 | * @param cert The certificate to install. |
| 3689 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3690 | * with that alias already exists, it will be overwritten. |
| 3691 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3692 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3693 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3694 | * @see #setDelegatedScopes |
| 3695 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3696 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3697 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3698 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3699 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | /** |
| 3703 | * 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] | 3704 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3705 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3706 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3707 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3708 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3709 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3710 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3711 | * |
| 3712 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3713 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3714 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3715 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3716 | * certificate and include the chain of trust in order. This will be returned by |
| 3717 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3718 | * @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] | 3719 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3720 | * @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] | 3721 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3722 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3723 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3724 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3725 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3726 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3727 | * @see #setDelegatedScopes |
| 3728 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3729 | */ |
| 3730 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3731 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3732 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3733 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3734 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3735 | byte[] pemChain = null; |
| 3736 | if (certs.length > 1) { |
| 3737 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3738 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3739 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3740 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3741 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3742 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3743 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3744 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3745 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3746 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3747 | } catch (CertificateException | IOException e) { |
| 3748 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3749 | } |
| 3750 | return false; |
| 3751 | } |
| 3752 | |
| 3753 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3754 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3755 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3756 | * |
| 3757 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3758 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3759 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3760 | * @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] | 3761 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3762 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3763 | * @see #setDelegatedScopes |
| 3764 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3765 | */ |
| 3766 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3767 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3768 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3769 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3770 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3771 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3772 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3776 | * @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] | 3777 | * doesn't exist. |
| 3778 | */ |
| 3779 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3780 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3781 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3782 | new ByteArrayInputStream(certBuffer)); |
| 3783 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3784 | } |
| 3785 | |
| 3786 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3787 | * 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] | 3788 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3789 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3790 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3791 | * <p> |
| 3792 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3793 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3794 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3795 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3796 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3797 | * 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] | 3798 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3799 | * {@link IllegalArgumentException} will be thrown. |
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. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3802 | * @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] | 3803 | * access. If {@code null} is given the current package will be cleared. |
| 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 #setDelegatedScopes} |
| 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 |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3810 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3811 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3812 | throwIfParentInstance("setCertInstallerPackage"); |
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 | mService.setCertInstallerPackage(admin, installerPackage); |
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 | } |
| 3821 | |
| 3822 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3823 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3824 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3825 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3826 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3827 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3828 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3829 | * none is set. |
| 3830 | * @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] | 3831 | * |
| 3832 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3833 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3834 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3835 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3836 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3837 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3838 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3839 | if (mService != null) { |
| 3840 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3841 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3842 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3843 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3844 | } |
| 3845 | } |
| 3846 | return null; |
| 3847 | } |
| 3848 | |
| 3849 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3850 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3851 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3852 | * constants. |
| 3853 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3854 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 3855 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 3856 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 3857 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 3858 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3859 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3860 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3861 | * {@code delegatePackage}. |
| 3862 | * |
| 3863 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3864 | * @param delegatePackage The package name of the app which will be given access. |
| 3865 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3866 | * {@code delegatedPackage}. |
| 3867 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3868 | */ |
| 3869 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3870 | @NonNull List<String> scopes) { |
| 3871 | throwIfParentInstance("setDelegatedScopes"); |
| 3872 | if (mService != null) { |
| 3873 | try { |
| 3874 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 3875 | } catch (RemoteException e) { |
| 3876 | throw e.rethrowFromSystemServer(); |
| 3877 | } |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | /** |
| 3882 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 3883 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 3884 | * passing {@code null} for {@code admin} and their own package name as |
| 3885 | * {@code delegatedPackage}. |
| 3886 | * |
| 3887 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3888 | * {@code null} if the caller is {@code delegatedPackage}. |
| 3889 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 3890 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 3891 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3892 | */ |
| 3893 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3894 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3895 | @NonNull String delegatedPackage) { |
| 3896 | throwIfParentInstance("getDelegatedScopes"); |
| 3897 | if (mService != null) { |
| 3898 | try { |
| 3899 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 3900 | } catch (RemoteException e) { |
| 3901 | throw e.rethrowFromSystemServer(); |
| 3902 | } |
| 3903 | } |
| 3904 | return null; |
| 3905 | } |
| 3906 | |
| 3907 | /** |
| 3908 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 3909 | * granted a delegation scope. |
| 3910 | * |
| 3911 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3912 | * @param delegationScope The scope whose delegates should be retrieved. |
| 3913 | * @return A list of package names of the current delegated packages for |
| 3914 | {@code delegationScope}. |
| 3915 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3916 | */ |
| 3917 | @Nullable |
| 3918 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 3919 | @NonNull String delegationScope) { |
| 3920 | throwIfParentInstance("getDelegatePackages"); |
| 3921 | if (mService != null) { |
| 3922 | try { |
| 3923 | return mService.getDelegatePackages(admin, delegationScope); |
| 3924 | } catch (RemoteException e) { |
| 3925 | throw e.rethrowFromSystemServer(); |
| 3926 | } |
| 3927 | } |
| 3928 | return null; |
| 3929 | } |
| 3930 | |
| 3931 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3932 | * 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] | 3933 | * specific application for the current user. |
| 3934 | * |
| 3935 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3936 | * TODO: delete once there are no longer any live references. |
| 3937 | * @hide |
| 3938 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3939 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3940 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3941 | throws NameNotFoundException, UnsupportedOperationException { |
| 3942 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3943 | } |
| 3944 | |
| 3945 | /** |
| 3946 | * 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] | 3947 | * specific application for the current user. This connection is automatically granted and |
| 3948 | * persisted after a reboot. |
| 3949 | * <p> |
| 3950 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3951 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3952 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3953 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3954 | * @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] | 3955 | * remove an existing always-on VPN configuration. |
| 3956 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3957 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3958 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3959 | * @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] | 3960 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3961 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3962 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3963 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3964 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3965 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3966 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3967 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3968 | if (mService != null) { |
| 3969 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3970 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3971 | throw new NameNotFoundException(vpnPackage); |
| 3972 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3973 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3974 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3975 | } |
| 3976 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | /** |
| 3980 | * 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] | 3981 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3982 | * 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] | 3983 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3984 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3985 | * is set. |
| 3986 | * @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] | 3987 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3988 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3989 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3990 | if (mService != null) { |
| 3991 | try { |
| 3992 | return mService.getAlwaysOnVpnPackage(admin); |
| 3993 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3994 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3995 | } |
| 3996 | } |
| 3997 | return null; |
| 3998 | } |
| 3999 | |
| 4000 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4001 | * Called by an application that is administering the device to disable all cameras on the |
| 4002 | * device, for this user. After setting this, no applications running as this user will be able |
| 4003 | * to access any cameras on the device. |
| 4004 | * <p> |
| 4005 | * If the caller is device owner, then the restriction will be applied to all users. |
| 4006 | * <p> |
| 4007 | * The calling device admin must have requested |
| 4008 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 4009 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4010 | * |
| 4011 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4012 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4013 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4014 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4015 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4016 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4017 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4018 | if (mService != null) { |
| 4019 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4020 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4021 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4022 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4023 | } |
| 4024 | } |
| 4025 | } |
| 4026 | |
| 4027 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4028 | * 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] | 4029 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4030 | * @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] | 4031 | * have disabled the camera |
| 4032 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4033 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4034 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4035 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4039 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4040 | if (mService != null) { |
| 4041 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4042 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4043 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4044 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4045 | } |
| 4046 | } |
| 4047 | return false; |
| 4048 | } |
| 4049 | |
| 4050 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4051 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4052 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 4053 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 4054 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 4055 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4056 | * |
| 4057 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4058 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 4059 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 4060 | * 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] | 4061 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 4062 | * 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] | 4063 | */ |
| 4064 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4065 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4066 | if (mService != null) { |
| 4067 | try { |
| 4068 | return mService.requestBugreport(admin); |
| 4069 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4070 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4071 | } |
| 4072 | } |
| 4073 | return false; |
| 4074 | } |
| 4075 | |
| 4076 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 4077 | * Determine whether or not creating a guest user has been disabled for the device |
| 4078 | * |
| 4079 | * @hide |
| 4080 | */ |
| 4081 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 4082 | // Currently guest users can always be created if multi-user is enabled |
| 4083 | // TODO introduce a policy for guest user creation |
| 4084 | return false; |
| 4085 | } |
| 4086 | |
| 4087 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 4088 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 4089 | * screen capture also prevents the content from being shown on display devices that do not have |
| 4090 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 4091 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4092 | * <p> |
| 4093 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4094 | * exception will be thrown. |
| 4095 | * <p> |
| 4096 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 4097 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 4098 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4099 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4100 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4101 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4102 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4103 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4104 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4105 | if (mService != null) { |
| 4106 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4107 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4108 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4109 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | } |
| 4113 | |
| 4114 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4115 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4116 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4117 | * @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] | 4118 | * have disabled screen capture. |
| 4119 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4120 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4121 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4122 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4126 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4127 | if (mService != null) { |
| 4128 | try { |
| 4129 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 4130 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4131 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4132 | } |
| 4133 | } |
| 4134 | return false; |
| 4135 | } |
| 4136 | |
| 4137 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4138 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 4139 | * 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] | 4140 | * <p> |
| 4141 | * Note: if auto time is required the user can still manually set the time zone. |
| 4142 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4143 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4144 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4145 | * |
| 4146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4147 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4148 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4149 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4150 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4151 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4152 | if (mService != null) { |
| 4153 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4154 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4155 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4156 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4157 | } |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | /** |
| 4162 | * @return true if auto time is required. |
| 4163 | */ |
| 4164 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4165 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4166 | if (mService != null) { |
| 4167 | try { |
| 4168 | return mService.getAutoTimeRequired(); |
| 4169 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4170 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4171 | } |
| 4172 | } |
| 4173 | return false; |
| 4174 | } |
| 4175 | |
| 4176 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4177 | * 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] | 4178 | * <p> |
| 4179 | * The system user is exempt from this policy - it is never ephemeral. |
| 4180 | * <p> |
| 4181 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4182 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4183 | * |
| 4184 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4185 | * @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] | 4186 | * subsequently created users will be ephemeral. |
| 4187 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4188 | * @hide |
| 4189 | */ |
| 4190 | public void setForceEphemeralUsers( |
| 4191 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4192 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4193 | if (mService != null) { |
| 4194 | try { |
| 4195 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 4196 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4197 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4198 | } |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | /** |
| 4203 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4204 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4205 | * @hide |
| 4206 | */ |
| 4207 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4208 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4209 | if (mService != null) { |
| 4210 | try { |
| 4211 | return mService.getForceEphemeralUsers(admin); |
| 4212 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4213 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4214 | } |
| 4215 | } |
| 4216 | return false; |
| 4217 | } |
| 4218 | |
| 4219 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4220 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4221 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4222 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4223 | * <p> |
| 4224 | * The calling device admin must have requested |
| 4225 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4226 | * if it has not, a security exception will be thrown. |
| 4227 | * <p> |
| 4228 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4229 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4230 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4231 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4232 | * <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] | 4233 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4234 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4235 | * there is one, or the parent user otherwise. |
| 4236 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4237 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4238 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4239 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4240 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4241 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4242 | * profile. |
| 4243 | * <p> |
| 4244 | * Requests to disable other features on a managed profile will be ignored. |
| 4245 | * <p> |
| 4246 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4247 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4248 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4249 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4250 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4251 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4252 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4253 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4254 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4255 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4256 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4257 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4258 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4259 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4260 | if (mService != null) { |
| 4261 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4262 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4263 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4264 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4265 | } |
| 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4270 | * 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] | 4271 | * 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] | 4272 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4273 | * |
| 4274 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4275 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4276 | * restrictions on the parent profile. |
| 4277 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4278 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4279 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4280 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4281 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4282 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4283 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4284 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4288 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4289 | if (mService != null) { |
| 4290 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4291 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4292 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4293 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4294 | } |
| 4295 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4296 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4300 | * @hide |
| 4301 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4302 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4303 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4304 | if (mService != null) { |
| 4305 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4306 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4307 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4308 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4309 | } |
| 4310 | } |
| 4311 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4312 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4313 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4314 | * @hide |
| 4315 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4316 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4317 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4321 | * @hide |
| 4322 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4323 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4324 | if (mService != null) { |
| 4325 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4326 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4327 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4328 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4329 | } |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | /** |
| 4334 | * @hide |
| 4335 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4336 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4337 | if (mService != null) { |
| 4338 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4339 | mService.setActivePasswordState(metrics, 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 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4349 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4350 | if (mService != null) { |
| 4351 | try { |
| 4352 | mService.reportPasswordChanged(userId); |
| 4353 | } catch (RemoteException e) { |
| 4354 | throw e.rethrowFromSystemServer(); |
| 4355 | } |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | /** |
| 4360 | * @hide |
| 4361 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4362 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4363 | if (mService != null) { |
| 4364 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4365 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4366 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4367 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4368 | } |
| 4369 | } |
| 4370 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4371 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4372 | /** |
| 4373 | * @hide |
| 4374 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4375 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4376 | if (mService != null) { |
| 4377 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4378 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4379 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4380 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4381 | } |
| 4382 | } |
| 4383 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4384 | |
| 4385 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4386 | * @hide |
| 4387 | */ |
| 4388 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4389 | if (mService != null) { |
| 4390 | try { |
| 4391 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4392 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4393 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4394 | } |
| 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | /** |
| 4399 | * @hide |
| 4400 | */ |
| 4401 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4402 | if (mService != null) { |
| 4403 | try { |
| 4404 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4405 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4406 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4407 | } |
| 4408 | } |
| 4409 | } |
| 4410 | |
| 4411 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4412 | * Should be called when keyguard has been dismissed. |
| 4413 | * @hide |
| 4414 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4415 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4416 | if (mService != null) { |
| 4417 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4418 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4419 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4420 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4421 | } |
| 4422 | } |
| 4423 | } |
| 4424 | |
| 4425 | /** |
| 4426 | * Should be called when keyguard view has been shown to the user. |
| 4427 | * @hide |
| 4428 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4429 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4430 | if (mService != null) { |
| 4431 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4432 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4433 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4434 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4435 | } |
| 4436 | } |
| 4437 | } |
| 4438 | |
| 4439 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4440 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4441 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4442 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4443 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4444 | * @return whether the package was successfully registered as the device owner. |
| 4445 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4446 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4447 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4448 | public boolean setDeviceOwner(ComponentName who) { |
| 4449 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | /** |
| 4453 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4454 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4455 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4456 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4457 | } |
| 4458 | |
| 4459 | /** |
| 4460 | * @hide |
| 4461 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4462 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4463 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | /** |
| 4467 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4468 | * Sets the given package as the device owner. The package must already be installed. There |
| 4469 | * must not already be a device owner. |
| 4470 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4471 | * this method. |
| 4472 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4473 | * 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] | 4474 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4475 | * @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] | 4476 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4477 | * @return whether the package was successfully registered as the device owner. |
| 4478 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4479 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4480 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4481 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4482 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4483 | if (mService != null) { |
| 4484 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4485 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4486 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4487 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4488 | } |
| 4489 | } |
| 4490 | return false; |
| 4491 | } |
| 4492 | |
| 4493 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4494 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4495 | * 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] | 4496 | * 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] | 4497 | * package is currently registered as the device owner app, pass in the package name from |
| 4498 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4499 | * 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] | 4500 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4501 | * the setup process. |
| 4502 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4503 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4504 | * @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] | 4505 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4506 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4507 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4508 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4509 | } |
| 4510 | |
| 4511 | /** |
| 4512 | * @return true if a package is registered as device owner, only when it's running on the |
| 4513 | * calling user. |
| 4514 | * |
| 4515 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4516 | * @hide |
| 4517 | */ |
| 4518 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4519 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4520 | } |
| 4521 | |
| 4522 | /** |
| 4523 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4524 | * user. |
| 4525 | * |
| 4526 | * <p>Requires the MANAGE_USERS permission. |
| 4527 | * |
| 4528 | * @hide |
| 4529 | */ |
| 4530 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4531 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4532 | } |
| 4533 | |
| 4534 | /** |
| 4535 | * @return device owner component name, only when it's running on the calling user. |
| 4536 | * |
| 4537 | * @hide |
| 4538 | */ |
| 4539 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4540 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4541 | } |
| 4542 | |
| 4543 | /** |
| 4544 | * @return device owner component name, even if it's running on a different user. |
| 4545 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4546 | * @hide |
| 4547 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4548 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4549 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4550 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4551 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4552 | } |
| 4553 | |
| 4554 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4555 | if (packageName == null) { |
| 4556 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4557 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4558 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4559 | if (deviceOwner == null) { |
| 4560 | return false; |
| 4561 | } |
| 4562 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4563 | } |
| 4564 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4565 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4566 | if (mService != null) { |
| 4567 | try { |
| 4568 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4569 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4570 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4571 | } |
| 4572 | } |
| 4573 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4574 | } |
| 4575 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4576 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4577 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4578 | * no device owner. |
| 4579 | * |
| 4580 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4581 | * |
| 4582 | * @hide |
| 4583 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4584 | public int getDeviceOwnerUserId() { |
| 4585 | if (mService != null) { |
| 4586 | try { |
| 4587 | return mService.getDeviceOwnerUserId(); |
| 4588 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4589 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4596 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4597 | * 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] | 4598 | * a part of device setup, before it completes. |
| 4599 | * <p> |
| 4600 | * While some policies previously set by the device owner will be cleared by this method, it is |
| 4601 | * a best-effort process and some other policies will still remain in place after the device |
| 4602 | * owner is cleared. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4603 | * |
| 4604 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4605 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4606 | * does not own the current device owner component. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4607 | * |
| 4608 | * @deprecated This method is expected to be used for testing purposes only. The device owner |
| 4609 | * will lose control of the device and its data after calling it. In order to protect any |
| 4610 | * sensitive data that remains on the device, it is advised that the device owner factory resets |
| 4611 | * the device instead of calling this method. See {@link #wipeData(int)}. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4612 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4613 | @Deprecated |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4614 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4615 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4616 | if (mService != null) { |
| 4617 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4618 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4619 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4620 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | } |
| 4624 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4625 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4626 | * Returns the device owner package name, only if it's running on the calling user. |
| 4627 | * |
| 4628 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4629 | * |
| 4630 | * @hide |
| 4631 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4632 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4633 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4634 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4635 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4636 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4637 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4641 | * 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] | 4642 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4643 | * @return whether the device is managed by a Device Owner. |
| 4644 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4645 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4646 | * |
| 4647 | * @hide |
| 4648 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4649 | @SystemApi |
| 4650 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4651 | @SuppressLint("Doclava125") |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4652 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4653 | try { |
| 4654 | return mService.hasDeviceOwner(); |
| 4655 | } catch (RemoteException re) { |
| 4656 | throw re.rethrowFromSystemServer(); |
| 4657 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | /** |
| 4661 | * Returns the device owner name. Note this method *will* return the device owner |
| 4662 | * name when it's running on a different user. |
| 4663 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4664 | * @hide |
| 4665 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4666 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4667 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4668 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4669 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4670 | if (mService != null) { |
| 4671 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4672 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4673 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4674 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4675 | } |
| 4676 | } |
| 4677 | return null; |
| 4678 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4679 | |
| 4680 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4681 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4682 | * @deprecated Do not use |
| 4683 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4684 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4685 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4686 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4687 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4688 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4689 | return null; |
| 4690 | } |
| 4691 | |
| 4692 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4693 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4694 | * @deprecated Do not use |
| 4695 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4696 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4697 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4698 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4699 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4700 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4701 | return null; |
| 4702 | } |
| 4703 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4704 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4705 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4706 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4707 | * Sets the given component as an active admin and registers the package as the profile |
| 4708 | * owner for this user. The package must already be installed and there shouldn't be |
| 4709 | * an existing profile owner registered for this user. Also, this method must be called |
| 4710 | * before the user setup has been completed. |
| 4711 | * <p> |
| 4712 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4713 | * MANAGE_DEVICE_ADMINS permission. |
| 4714 | * @param admin The component to register as an active admin and profile owner. |
| 4715 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4716 | * @return whether the admin was successfully registered as the profile owner. |
| 4717 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4718 | * the user has already been set up. |
| 4719 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4720 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4721 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4722 | @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4723 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4724 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4725 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4726 | if (mService != null) { |
| 4727 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4728 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4729 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4730 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4731 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4732 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | return false; |
| 4736 | } |
| 4737 | |
| 4738 | /** |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4739 | * Clears the active profile owner. The caller must be the profile owner of this user, otherwise |
| 4740 | * 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] | 4741 | * <p> |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4742 | * While some policies previously set by the profile owner will be cleared by this method, it is |
| 4743 | * a best-effort process and some other policies will still remain in place after the profile |
| 4744 | * owner is cleared. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4745 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4746 | * @param admin The component to remove as the profile owner. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4747 | * @throws SecurityException if {@code admin} is not an active profile owner, or the method is |
| 4748 | * being called from a managed profile. |
| 4749 | * |
| 4750 | * @deprecated This method is expected to be used for testing purposes only. The profile owner |
| 4751 | * will lose control of the user and its data after calling it. In order to protect any |
| 4752 | * sensitive data that remains on this user, it is advised that the profile owner deletes it |
| 4753 | * instead of calling this method. See {@link #wipeData(int)}. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4754 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4755 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4756 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4757 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4758 | if (mService != null) { |
| 4759 | try { |
| 4760 | mService.clearProfileOwner(admin); |
| 4761 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4762 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4768 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4769 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4770 | */ |
| 4771 | public boolean hasUserSetupCompleted() { |
| 4772 | if (mService != null) { |
| 4773 | try { |
| 4774 | return mService.hasUserSetupCompleted(); |
| 4775 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4776 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4777 | } |
| 4778 | } |
| 4779 | return true; |
| 4780 | } |
| 4781 | |
| 4782 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4783 | * @hide |
| 4784 | * 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] | 4785 | * already be installed. There must not already be a profile owner for this user. |
| 4786 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4787 | * this method. |
| 4788 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4789 | * - the caller is SYSTEM_UID. |
| 4790 | * - 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] | 4791 | * @param admin the component name to be registered as profile owner. |
| 4792 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4793 | * @param userHandle the userId to set the profile owner for. |
| 4794 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4795 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4796 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4797 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4798 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4799 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4800 | if (mService != null) { |
| 4801 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4802 | if (ownerName == null) { |
| 4803 | ownerName = ""; |
| 4804 | } |
| 4805 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4806 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4807 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4808 | } |
| 4809 | } |
| 4810 | return false; |
| 4811 | } |
| 4812 | |
| 4813 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4814 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4815 | * <p> |
| 4816 | * 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] | 4817 | * 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] | 4818 | * <p> |
| 4819 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4820 | * will be blank and the user will not be allowed to change it. |
| 4821 | * <p> |
| 4822 | * 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] | 4823 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4824 | * and set a new version of this string accordingly. |
| 4825 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4826 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4827 | * @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] | 4828 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4829 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4830 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4831 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4832 | if (mService != null) { |
| 4833 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4834 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4835 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4836 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4837 | } |
| 4838 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | /** |
| 4842 | * @return The device owner information. If it is not set returns {@code null}. |
| 4843 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4844 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4845 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4846 | if (mService != null) { |
| 4847 | try { |
| 4848 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4849 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4850 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4851 | } |
| 4852 | } |
| 4853 | return null; |
| 4854 | } |
| 4855 | |
| 4856 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4857 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4858 | * called by a device owner, profile owner, or by a delegate given the |
| 4859 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4860 | * <p> |
| 4861 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4862 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4863 | * device. |
| 4864 | * <p> |
| 4865 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4866 | * 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] | 4867 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4868 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4869 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4870 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4871 | * @param packageNames The package names to suspend or unsuspend. |
| 4872 | * @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] | 4873 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4874 | * @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] | 4875 | * this method. |
| 4876 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4877 | * @see #setDelegatedScopes |
| 4878 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4879 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4880 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4881 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4882 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4883 | if (mService != null) { |
| 4884 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4885 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 4886 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4887 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4888 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4889 | } |
| 4890 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4891 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4895 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 4896 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 4897 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4898 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4899 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4900 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4901 | * @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] | 4902 | * @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] | 4903 | * suspended, could not be found or an error occurred. |
| 4904 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4905 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4906 | * @see #setDelegatedScopes |
| 4907 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4908 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4909 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4910 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4911 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4912 | if (mService != null) { |
| 4913 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4914 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4915 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4916 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4917 | } catch (IllegalArgumentException ex) { |
| 4918 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4919 | } |
| 4920 | } |
| 4921 | return false; |
| 4922 | } |
| 4923 | |
| 4924 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4925 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4926 | * be used. Only the profile owner can call this. |
| 4927 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4928 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4929 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4930 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4931 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4932 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4933 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4934 | if (mService != null) { |
| 4935 | try { |
| 4936 | mService.setProfileEnabled(admin); |
| 4937 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4938 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4939 | } |
| 4940 | } |
| 4941 | } |
| 4942 | |
| 4943 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4944 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4945 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4946 | * 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] | 4947 | * |
| 4948 | * @see #isProfileOwnerApp |
| 4949 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4950 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4951 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4952 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4953 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4954 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4955 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4956 | if (mService != null) { |
| 4957 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4958 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4959 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4960 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4961 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4962 | } |
| 4963 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4964 | |
| 4965 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4966 | * 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] | 4967 | * 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] | 4968 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4969 | * |
| 4970 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4971 | * @return Whether or not the package is registered as the profile owner. |
| 4972 | */ |
| 4973 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4974 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4975 | if (mService != null) { |
| 4976 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4977 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4978 | return profileOwner != null |
| 4979 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4980 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4981 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4982 | } |
| 4983 | } |
| 4984 | return false; |
| 4985 | } |
| 4986 | |
| 4987 | /** |
| 4988 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4989 | * @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] | 4990 | * owner has been set for that user. |
| 4991 | * @throws IllegalArgumentException if the userId is invalid. |
| 4992 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4993 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4994 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4995 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4996 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4997 | } |
| 4998 | |
| 4999 | /** |
| 5000 | * @see #getProfileOwner() |
| 5001 | * @hide |
| 5002 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5003 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 5004 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5005 | if (mService != null) { |
| 5006 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 5007 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5008 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5009 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5010 | } |
| 5011 | } |
| 5012 | return null; |
| 5013 | } |
| 5014 | |
| 5015 | /** |
| 5016 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5017 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 5018 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5019 | * @throws IllegalArgumentException if the userId is invalid. |
| 5020 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5021 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5022 | if (mService != null) { |
| 5023 | try { |
| 5024 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 5025 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5026 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | return null; |
| 5030 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5031 | |
| 5032 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5033 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5034 | * @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] | 5035 | * @return the human readable name of the organisation associated with this profile owner or |
| 5036 | * null if one is not set. |
| 5037 | * @throws IllegalArgumentException if the userId is invalid. |
| 5038 | */ |
| 5039 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5040 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5041 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5042 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5043 | if (mService != null) { |
| 5044 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 5045 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5046 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5047 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5048 | } |
| 5049 | } |
| 5050 | return null; |
| 5051 | } |
| 5052 | |
| 5053 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5054 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 5055 | * 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] | 5056 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 5057 | * intent preferences are reset. |
| 5058 | * <p> |
| 5059 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 5060 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 5061 | * the filter. |
| 5062 | * <p> |
| 5063 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 5064 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5065 | * |
| 5066 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5067 | * @param filter The IntentFilter for which a default handler is added. |
| 5068 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5069 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5070 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5071 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 5072 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5073 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5074 | if (mService != null) { |
| 5075 | try { |
| 5076 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 5077 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5078 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5079 | } |
| 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | /** |
| 5084 | * 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] | 5085 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5086 | * <p> |
| 5087 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5088 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5089 | * |
| 5090 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5091 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5092 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5093 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5094 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5095 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5096 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5097 | if (mService != null) { |
| 5098 | try { |
| 5099 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 5100 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5101 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5105 | |
| 5106 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5107 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 5108 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 5109 | * {@link #getApplicationRestrictions}. |
| 5110 | * <p> |
| 5111 | * This permission is persistent until it is later cleared by calling this method with a |
| 5112 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 5113 | * <p> |
| 5114 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5115 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5116 | * |
| 5117 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5118 | * @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] | 5119 | * APIs. If {@code null} is given the current package will be cleared. |
| 5120 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5121 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5122 | * |
| 5123 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 5124 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5125 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5126 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5127 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5128 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5129 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5130 | if (mService != null) { |
| 5131 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5132 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 5133 | throw new NameNotFoundException(packageName); |
| 5134 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5135 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5136 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5137 | } |
| 5138 | } |
| 5139 | } |
| 5140 | |
| 5141 | /** |
| 5142 | * 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] | 5143 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 5144 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5145 | * |
| 5146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5147 | * @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] | 5148 | * {@code null} if none is set. |
| 5149 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
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 #getDelegatePackages} |
| 5152 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope 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 |
| 5155 | @Nullable |
| 5156 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5157 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5158 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5159 | if (mService != null) { |
| 5160 | try { |
| 5161 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 5162 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5163 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5164 | } |
| 5165 | } |
| 5166 | return null; |
| 5167 | } |
| 5168 | |
| 5169 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 5170 | * Called by any application to find out whether it has been granted permission via |
| 5171 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 5172 | * for the calling user. |
| 5173 | * |
| 5174 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 5175 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5176 | * |
| 5177 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 5178 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5179 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5180 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5181 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5182 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5183 | if (mService != null) { |
| 5184 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5185 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 5186 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5187 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5188 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5189 | } |
| 5190 | } |
| 5191 | return false; |
| 5192 | } |
| 5193 | |
| 5194 | /** |
| 5195 | * 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] | 5196 | * <p> |
| 5197 | * 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] | 5198 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5199 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5200 | * <p> |
| 5201 | * 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] | 5202 | * <ul> |
| 5203 | * <li>{@code boolean} |
| 5204 | * <li>{@code int} |
| 5205 | * <li>{@code String} or {@code String[]} |
| 5206 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5207 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5208 | * <p> |
| 5209 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5210 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5211 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5212 | * <p> |
| 5213 | * The application restrictions are only made visible to the target application via |
| 5214 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5215 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5216 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5217 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5218 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5219 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5220 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5221 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5222 | * @param packageName The name of the package to update restricted settings for. |
| 5223 | * @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] | 5224 | * set of active restrictions. |
| 5225 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5226 | * @see #setDelegatedScopes |
| 5227 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5228 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5229 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5230 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5231 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5232 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5233 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5234 | if (mService != null) { |
| 5235 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5236 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5237 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5238 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5239 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5240 | } |
| 5241 | } |
| 5242 | } |
| 5243 | |
| 5244 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5245 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 5246 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5247 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5248 | * {@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] | 5249 | * <p> |
| 5250 | * The calling device admin must have requested |
| 5251 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5252 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5253 | * <p> |
| 5254 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5255 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5256 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5257 | * |
| 5258 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5259 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5260 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5261 | * strictly disabled according to the state of the |
| 5262 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5263 | * <p> |
| 5264 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5265 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5266 | * device admins. |
| 5267 | * <p> |
| 5268 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5269 | * parameters. |
| 5270 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5271 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5272 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5273 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5274 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5275 | if (mService != null) { |
| 5276 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5277 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5278 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5279 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5280 | } |
| 5281 | } |
| 5282 | } |
| 5283 | |
| 5284 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5285 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5286 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5287 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5288 | * <p> |
| 5289 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5290 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5291 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5292 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5293 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5294 | * this function returns a list of configurations for all admins that declare |
| 5295 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5296 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5297 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5298 | * 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] | 5299 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5300 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5301 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5302 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5303 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5304 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5308 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5309 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5310 | if (mService != null) { |
| 5311 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5312 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5313 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5314 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5315 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5316 | } |
| 5317 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5318 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5322 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5323 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5324 | * <p> |
| 5325 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5326 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5327 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5328 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5329 | * @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] | 5330 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5331 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5332 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5333 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5334 | if (mService != null) { |
| 5335 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5336 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5337 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5338 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5339 | } |
| 5340 | } |
| 5341 | } |
| 5342 | |
| 5343 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5344 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5345 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5346 | * <p> |
| 5347 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5348 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5349 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5350 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5351 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5352 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5353 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5354 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5355 | if (mService != null) { |
| 5356 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5357 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5358 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5359 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5360 | } |
| 5361 | } |
| 5362 | return false; |
| 5363 | } |
| 5364 | |
| 5365 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5366 | * Determine whether or not caller-Id information has been disabled. |
| 5367 | * |
| 5368 | * @param userHandle The user for whom to check the caller-id permission |
| 5369 | * @hide |
| 5370 | */ |
| 5371 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5372 | if (mService != null) { |
| 5373 | try { |
| 5374 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5375 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5376 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5377 | } |
| 5378 | } |
| 5379 | return false; |
| 5380 | } |
| 5381 | |
| 5382 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5383 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5384 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5385 | * <p> |
| 5386 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5387 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5388 | * |
| 5389 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5390 | * @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] | 5391 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5392 | */ |
| 5393 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5394 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5395 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5396 | if (mService != null) { |
| 5397 | try { |
| 5398 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5399 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5400 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5401 | } |
| 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | /** |
| 5406 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5407 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5408 | * <p> |
| 5409 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5410 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5411 | * |
| 5412 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5413 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5414 | */ |
| 5415 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5416 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5417 | if (mService != null) { |
| 5418 | try { |
| 5419 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 5420 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5421 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5422 | } |
| 5423 | } |
| 5424 | return false; |
| 5425 | } |
| 5426 | |
| 5427 | |
| 5428 | /** |
| 5429 | * Determine whether or not contacts search has been disabled. |
| 5430 | * |
| 5431 | * @param userHandle The user for whom to check the contacts search permission |
| 5432 | * @hide |
| 5433 | */ |
| 5434 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5435 | if (mService != null) { |
| 5436 | try { |
| 5437 | return mService |
| 5438 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5439 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5440 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5441 | } |
| 5442 | } |
| 5443 | return false; |
| 5444 | } |
| 5445 | |
| 5446 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5447 | * 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] | 5448 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5449 | * @hide |
| 5450 | */ |
| 5451 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5452 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5453 | if (mService != null) { |
| 5454 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5455 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5456 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5457 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5458 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5459 | } |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5464 | * 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] | 5465 | * @hide |
| 5466 | */ |
| 5467 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5468 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5469 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5470 | originalIntent); |
| 5471 | } |
| 5472 | |
| 5473 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5474 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5475 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5476 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5477 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5478 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5479 | * <p> |
| 5480 | * This API works on managed profile only. |
| 5481 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5482 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5483 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5484 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5485 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5486 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5487 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5488 | if (mService != null) { |
| 5489 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5490 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5491 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5492 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5493 | } |
| 5494 | } |
| 5495 | } |
| 5496 | |
| 5497 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5498 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5499 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5500 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5501 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5502 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5503 | * <p> |
| 5504 | * This API works on managed profile only. |
| 5505 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5506 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5507 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5508 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5509 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5510 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5511 | if (mService != null) { |
| 5512 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5513 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5514 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5515 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5516 | } |
| 5517 | } |
| 5518 | return true; |
| 5519 | } |
| 5520 | |
| 5521 | /** |
| 5522 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5523 | * <p> |
| 5524 | * This API works on managed profile UserHandle only. |
| 5525 | * |
| 5526 | * @param userHandle The user for whom to check the caller-id permission |
| 5527 | * @hide |
| 5528 | */ |
| 5529 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5530 | if (mService != null) { |
| 5531 | try { |
| 5532 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5533 | .getIdentifier()); |
| 5534 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5535 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5536 | } |
| 5537 | } |
| 5538 | return true; |
| 5539 | } |
| 5540 | |
| 5541 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5542 | * 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] | 5543 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5544 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5545 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5546 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5547 | * @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] | 5548 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5549 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5550 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5551 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5552 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5553 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5554 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5555 | if (mService != null) { |
| 5556 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5557 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5558 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5559 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5560 | } |
| 5561 | } |
| 5562 | } |
| 5563 | |
| 5564 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5565 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5566 | * 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] | 5567 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5568 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5569 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5570 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5571 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5572 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5573 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5574 | if (mService != null) { |
| 5575 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5576 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5577 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5578 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5579 | } |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5584 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5585 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5586 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5587 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5588 | * the list and not part of the system can not be enabled by the user. |
| 5589 | * <p> |
| 5590 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5591 | * used, calling with an empty list only allows the builtin system's services. |
| 5592 | * <p> |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5593 | * 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] | 5594 | * |
| 5595 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5596 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5597 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5598 | * accessibility services enabled, that are not in the list. |
| 5599 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5600 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5601 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5602 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5603 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5604 | if (mService != null) { |
| 5605 | try { |
| 5606 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5607 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5608 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5609 | } |
| 5610 | } |
| 5611 | return false; |
| 5612 | } |
| 5613 | |
| 5614 | /** |
| 5615 | * 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] | 5616 | * <p> |
| 5617 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5618 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5619 | * |
| 5620 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5621 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5622 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5623 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5624 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5625 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5626 | if (mService != null) { |
| 5627 | try { |
| 5628 | return mService.getPermittedAccessibilityServices(admin); |
| 5629 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5630 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5631 | } |
| 5632 | } |
| 5633 | return null; |
| 5634 | } |
| 5635 | |
| 5636 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5637 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5638 | * |
| 5639 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5640 | * @param packageName Accessibility service package name that needs to be checked. |
| 5641 | * @param userHandle user id the admin is running as. |
| 5642 | * @return true if the accessibility service is permitted, otherwise false. |
| 5643 | * |
| 5644 | * @hide |
| 5645 | */ |
| 5646 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5647 | @NonNull String packageName, int userHandle) { |
| 5648 | if (mService != null) { |
| 5649 | try { |
| 5650 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5651 | userHandle); |
| 5652 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5653 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5654 | } |
| 5655 | } |
| 5656 | return false; |
| 5657 | } |
| 5658 | |
| 5659 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5660 | * Returns the list of accessibility services permitted by the device or profiles |
| 5661 | * owners of this user. |
| 5662 | * |
| 5663 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5664 | * it will contain the intersection of the permitted lists for any device or profile |
| 5665 | * owners that apply to this user. It will also include any system accessibility services. |
| 5666 | * |
| 5667 | * @param userId which user to check for. |
| 5668 | * @return List of accessiblity service package names. |
| 5669 | * @hide |
| 5670 | */ |
| 5671 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5672 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5673 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5674 | if (mService != null) { |
| 5675 | try { |
| 5676 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5677 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5678 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5679 | } |
| 5680 | } |
| 5681 | return null; |
| 5682 | } |
| 5683 | |
| 5684 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5685 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5686 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5687 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5688 | * When zero or more packages have been added, input method that are not in the list and not |
| 5689 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5690 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5691 | * <p> |
| 5692 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5693 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5694 | * <p> |
| 5695 | * 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] | 5696 | * |
| 5697 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5698 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5699 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5700 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5701 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5702 | */ |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5703 | public boolean setPermittedInputMethods( |
| 5704 | @NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5705 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5706 | if (mService != null) { |
| 5707 | try { |
| 5708 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5709 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5710 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5711 | } |
| 5712 | } |
| 5713 | return false; |
| 5714 | } |
| 5715 | |
| 5716 | |
| 5717 | /** |
| 5718 | * 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] | 5719 | * <p> |
| 5720 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5721 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5722 | * |
| 5723 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5724 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5725 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5726 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5727 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5728 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5729 | if (mService != null) { |
| 5730 | try { |
| 5731 | return mService.getPermittedInputMethods(admin); |
| 5732 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5733 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5734 | } |
| 5735 | } |
| 5736 | return null; |
| 5737 | } |
| 5738 | |
| 5739 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5740 | * Called by the system to check if a specific input method is disabled by admin. |
| 5741 | * |
| 5742 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5743 | * @param packageName Input method package name that needs to be checked. |
| 5744 | * @param userHandle user id the admin is running as. |
| 5745 | * @return true if the input method is permitted, otherwise false. |
| 5746 | * |
| 5747 | * @hide |
| 5748 | */ |
| 5749 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5750 | @NonNull String packageName, int userHandle) { |
| 5751 | if (mService != null) { |
| 5752 | try { |
| 5753 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5754 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5755 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | return false; |
| 5759 | } |
| 5760 | |
| 5761 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5762 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5763 | * 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] | 5764 | * |
| 5765 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5766 | * it will contain the intersection of the permitted lists for any device or profile |
| 5767 | * owners that apply to this user. It will also include any system input methods. |
| 5768 | * |
| 5769 | * @return List of input method package names. |
| 5770 | * @hide |
| 5771 | */ |
| 5772 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5773 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5774 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5775 | if (mService != null) { |
| 5776 | try { |
| 5777 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5778 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5779 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5780 | } |
| 5781 | } |
| 5782 | return null; |
| 5783 | } |
| 5784 | |
| 5785 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5786 | * Called by a profile owner of a managed profile to set the packages that are allowed to use |
| 5787 | * a {@link android.service.notification.NotificationListenerService} in the primary user to |
| 5788 | * see notifications from the managed profile. By default all packages are permitted by this |
| 5789 | * policy. When zero or more packages have been added, notification listeners installed on the |
| 5790 | * primary user that are not in the list and are not part of the system won't receive events |
| 5791 | * for managed profile notifications. |
| 5792 | * <p> |
| 5793 | * Calling with a {@code null} value for the list disables the restriction so that all |
| 5794 | * notification listener services be used. Calling with an empty list disables all but the |
| 5795 | * system's own notification listeners. System notification listener services are always |
| 5796 | * available to the user. |
| 5797 | * <p> |
| 5798 | * If a device or profile owner want to stop notification listeners in their user from seeing |
| 5799 | * that user's notifications they should prevent that service from running instead (e.g. via |
| 5800 | * {@link #setApplicationHidden(ComponentName, String, boolean)}) |
| 5801 | * |
| 5802 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5803 | * @param packageList List of package names to whitelist |
| 5804 | * @return true if setting the restriction succeeded. It will fail if called outside a managed |
| 5805 | * profile |
| 5806 | * @throws SecurityException if {@code admin} is not a profile owner. |
| 5807 | * |
| 5808 | * @see android.service.notification.NotificationListenerService |
| 5809 | */ |
| 5810 | public boolean setPermittedCrossProfileNotificationListeners( |
| 5811 | @NonNull ComponentName admin, @Nullable List<String> packageList) { |
| 5812 | throwIfParentInstance("setPermittedCrossProfileNotificationListeners"); |
| 5813 | if (mService != null) { |
| 5814 | try { |
| 5815 | return mService.setPermittedCrossProfileNotificationListeners(admin, packageList); |
| 5816 | } catch (RemoteException e) { |
| 5817 | throw e.rethrowFromSystemServer(); |
| 5818 | } |
| 5819 | } |
| 5820 | return false; |
| 5821 | } |
| 5822 | |
| 5823 | /** |
| 5824 | * Returns the list of packages installed on the primary user that allowed to use a |
| 5825 | * {@link android.service.notification.NotificationListenerService} to receive |
| 5826 | * notifications from this managed profile, as set by the profile owner. |
| 5827 | * <p> |
| 5828 | * An empty list means no notification listener services except system ones are allowed. |
| 5829 | * A {@code null} return value indicates that all notification listeners are allowed. |
| 5830 | */ |
| 5831 | public @Nullable List<String> getPermittedCrossProfileNotificationListeners( |
| 5832 | @NonNull ComponentName admin) { |
| 5833 | throwIfParentInstance("getPermittedCrossProfileNotificationListeners"); |
| 5834 | if (mService != null) { |
| 5835 | try { |
| 5836 | return mService.getPermittedCrossProfileNotificationListeners(admin); |
| 5837 | } catch (RemoteException e) { |
| 5838 | throw e.rethrowFromSystemServer(); |
| 5839 | } |
| 5840 | } |
| 5841 | return null; |
| 5842 | } |
| 5843 | |
| 5844 | /** |
| 5845 | * Returns true if {@code NotificationListenerServices} from the given package are allowed to |
| 5846 | * receive events for notifications from the given user id. Can only be called by the system uid |
| 5847 | * |
| 5848 | * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List) |
| 5849 | * |
| 5850 | * @hide |
| 5851 | */ |
| 5852 | public boolean isNotificationListenerServicePermitted( |
| 5853 | @NonNull String packageName, @UserIdInt int userId) { |
| 5854 | if (mService != null) { |
| 5855 | try { |
| 5856 | return mService.isNotificationListenerServicePermitted(packageName, userId); |
| 5857 | } catch (RemoteException e) { |
| 5858 | throw e.rethrowFromSystemServer(); |
| 5859 | } |
| 5860 | } |
| 5861 | return true; |
| 5862 | } |
| 5863 | |
| 5864 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5865 | * Get the 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}. |
| 5868 | * <p> |
| 5869 | * 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] | 5870 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5872 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5873 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5874 | * @see #setDelegatedScopes |
| 5875 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5876 | * @hide |
| 5877 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5878 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5879 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5880 | if (mService != null) { |
| 5881 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5882 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5883 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5884 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5885 | } |
| 5886 | } |
| 5887 | return null; |
| 5888 | } |
| 5889 | |
| 5890 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5891 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 5892 | * function can be called by a device owner or by a delegate given the |
| 5893 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5894 | * |
| 5895 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5896 | * automatically pre-cached.</p> |
| 5897 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5898 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5899 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5900 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5901 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5902 | * @see #setDelegatedScopes |
| 5903 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5904 | * @hide |
| 5905 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5906 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5907 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5908 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5909 | if (mService != null) { |
| 5910 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5911 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5912 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5913 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5914 | } |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5919 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5920 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5921 | * created. If you need to persist an identifier for this user, use |
| 5922 | * {@link UserManager#getSerialNumberForUser}. |
| 5923 | * |
| 5924 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5925 | * @param name the user's name |
| 5926 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5927 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5928 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5929 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5930 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5931 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5932 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5933 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5934 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5935 | return null; |
| 5936 | } |
| 5937 | |
| 5938 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5939 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5940 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5941 | * created. If you need to persist an identifier for this user, use |
| 5942 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5943 | * immediately. |
| 5944 | * |
| 5945 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5946 | * as registered as an active admin on the new user. The profile owner package will be |
| 5947 | * installed on the new user if it already is installed on the device. |
| 5948 | * |
| 5949 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5950 | * profileOwnerComponent when onEnable is called. |
| 5951 | * |
| 5952 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5953 | * @param name the user's name |
| 5954 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5955 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5956 | * the user. |
| 5957 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5958 | * on the new user. |
| 5959 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5960 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5961 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5962 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5963 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5964 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5965 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5966 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5967 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5968 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5969 | return null; |
| 5970 | } |
| 5971 | |
| 5972 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5973 | * 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] | 5974 | */ |
| 5975 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5976 | |
| 5977 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5978 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5979 | * ephemeral. |
| 5980 | * @hide |
| 5981 | */ |
| 5982 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5983 | |
| 5984 | /** |
Christine Franks | 361b825 | 2017-06-23 18:12:46 -0700 | [diff] [blame^] | 5985 | * Flag used by {@link #createAndManageUser} to specify that the user should be created as a |
| 5986 | * demo user. |
| 5987 | * @hide |
| 5988 | */ |
| 5989 | public static final int MAKE_USER_DEMO = 0x0004; |
| 5990 | |
| 5991 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5992 | * Called by a device owner to create a user with the specified name and a given component of |
| 5993 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5994 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5995 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5996 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5997 | * <p> |
| 5998 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5999 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 6000 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 6001 | * on the new user. |
| 6002 | * <p> |
| 6003 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 6004 | * 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] | 6005 | * |
| 6006 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6007 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6008 | * @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] | 6009 | * same package as admin, otherwise no user is created and an |
| 6010 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6011 | * @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] | 6012 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6013 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6014 | * @see UserHandle |
| 6015 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6016 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6017 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6018 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6019 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 6020 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6021 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 6022 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6023 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6024 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6025 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6026 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6027 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6028 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6029 | } |
| 6030 | |
| 6031 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6032 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 6033 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6034 | * |
| 6035 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6036 | * @param userHandle the user to remove. |
| 6037 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6038 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6039 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6040 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6041 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6042 | try { |
| 6043 | return mService.removeUser(admin, userHandle); |
| 6044 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6045 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6050 | * Called by a device owner to switch the specified user to the foreground. |
| 6051 | * |
| 6052 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6053 | * @param userHandle the user to switch to; null will switch to primary. |
| 6054 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6055 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6056 | * @see Intent#ACTION_USER_FOREGROUND |
| 6057 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6058 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6059 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6060 | try { |
| 6061 | return mService.switchUser(admin, userHandle); |
| 6062 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6063 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6064 | } |
| 6065 | } |
| 6066 | |
| 6067 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6068 | * Retrieves the application restrictions for a given target application running in the calling |
| 6069 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6070 | * <p> |
| 6071 | * 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] | 6072 | * application restrictions via {@link #setDelegatedScopes} with the |
| 6073 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6074 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6075 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 6076 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6077 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6078 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6079 | * @param packageName The name of the package to fetch restricted settings of. |
| 6080 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6081 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 6082 | * {@link Bundle} if no restrictions have been set. |
| 6083 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6084 | * @see #setDelegatedScopes |
| 6085 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6086 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6087 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6088 | public @NonNull Bundle getApplicationRestrictions( |
| 6089 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6090 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6091 | if (mService != null) { |
| 6092 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6093 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 6094 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6095 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6096 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6097 | } |
| 6098 | } |
| 6099 | return null; |
| 6100 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6101 | |
| 6102 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6103 | * 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] | 6104 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6105 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6106 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6107 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6108 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6109 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6110 | * for the list of keys. |
| 6111 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6112 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6113 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6114 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6115 | if (mService != null) { |
| 6116 | try { |
| 6117 | mService.setUserRestriction(admin, key, true); |
| 6118 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6119 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6120 | } |
| 6121 | } |
| 6122 | } |
| 6123 | |
| 6124 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6125 | * 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] | 6126 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6127 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6128 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6129 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6130 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6131 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6132 | * for the list of keys. |
| 6133 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6134 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6135 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6136 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6137 | if (mService != null) { |
| 6138 | try { |
| 6139 | mService.setUserRestriction(admin, key, false); |
| 6140 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6141 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6142 | } |
| 6143 | } |
| 6144 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 6145 | |
| 6146 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6147 | * Called by a profile or device owner to get user restrictions set with |
| 6148 | * {@link #addUserRestriction(ComponentName, String)}. |
| 6149 | * <p> |
| 6150 | * 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] | 6151 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6152 | * {@link UserManager#getUserRestrictions()}. |
| 6153 | * |
| 6154 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6155 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6156 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6157 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6158 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6159 | Bundle ret = null; |
| 6160 | if (mService != null) { |
| 6161 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 6162 | ret = mService.getUserRestrictions(admin); |
| 6163 | } catch (RemoteException e) { |
| 6164 | throw e.rethrowFromSystemServer(); |
| 6165 | } |
| 6166 | } |
| 6167 | return ret == null ? new Bundle() : ret; |
| 6168 | } |
| 6169 | |
| 6170 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6171 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 6172 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 6173 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 6174 | * was disabled by an admin, and include a link for more information. The default content of |
| 6175 | * the dialog can be changed by the restricting admin via |
| 6176 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 6177 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 6178 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 6179 | * user restriction from {@link UserManager}, e.g. |
| 6180 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
| 6181 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 6182 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 6183 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 6184 | */ |
| 6185 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 6186 | throwIfParentInstance("createAdminSupportIntent"); |
| 6187 | if (mService != null) { |
| 6188 | try { |
| 6189 | return mService.createAdminSupportIntent(restriction); |
| 6190 | } catch (RemoteException e) { |
| 6191 | throw e.rethrowFromSystemServer(); |
| 6192 | } |
| 6193 | } |
| 6194 | return null; |
| 6195 | } |
| 6196 | |
| 6197 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6198 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 6199 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 6200 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6201 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6202 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6203 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6204 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6205 | * @param packageName The name of the package to hide or unhide. |
| 6206 | * @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] | 6207 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6208 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6209 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6210 | * @see #setDelegatedScopes |
| 6211 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6212 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6213 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6214 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6215 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6216 | if (mService != null) { |
| 6217 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6218 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 6219 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6220 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6221 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | return false; |
| 6225 | } |
| 6226 | |
| 6227 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6228 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 6229 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6230 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6231 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6232 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6233 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6234 | * @param packageName The name of the package to retrieve the hidden status of. |
| 6235 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6236 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6237 | * @see #setDelegatedScopes |
| 6238 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6240 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6241 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6242 | if (mService != null) { |
| 6243 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6244 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6245 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6246 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6247 | } |
| 6248 | } |
| 6249 | return false; |
| 6250 | } |
| 6251 | |
| 6252 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6253 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 6254 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6255 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6256 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6257 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6258 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6259 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6260 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6261 | * @see #setDelegatedScopes |
| 6262 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6263 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6264 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6265 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6266 | if (mService != null) { |
| 6267 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6268 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6269 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6270 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6271 | } |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6276 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 6277 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 6278 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6279 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6280 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6281 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6282 | * @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] | 6283 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6284 | * @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] | 6285 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6286 | * @see #setDelegatedScopes |
| 6287 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6288 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6289 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6290 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6291 | if (mService != null) { |
| 6292 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6293 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6294 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6295 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6296 | } |
| 6297 | } |
| 6298 | return 0; |
| 6299 | } |
| 6300 | |
| 6301 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 6302 | * Called by a device owner or profile owner to disable account management for a specific type |
| 6303 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6304 | * <p> |
| 6305 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 6306 | * exception will be thrown. |
| 6307 | * <p> |
| 6308 | * When account management is disabled for an account type, adding or removing an account of |
| 6309 | * that type will not be possible. |
| 6310 | * <p> |
| 6311 | * 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] | 6312 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 6313 | * management for a specific type is disabled. |
| 6314 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6315 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6316 | * @param accountType For which account management is disabled or enabled. |
| 6317 | * @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] | 6318 | * enabled (false). |
| 6319 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6320 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6321 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6322 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6323 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6324 | if (mService != null) { |
| 6325 | try { |
| 6326 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 6327 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6328 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6329 | } |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6334 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 6335 | * |
| 6336 | * <p> Account management can be disabled/enabled by calling |
| 6337 | * {@link #setAccountManagementDisabled}. |
| 6338 | * |
| 6339 | * @return a list of account types for which account management has been disabled. |
| 6340 | * |
| 6341 | * @see #setAccountManagementDisabled |
| 6342 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6343 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6344 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 6345 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | /** |
| 6349 | * @see #getAccountTypesWithManagementDisabled() |
| 6350 | * @hide |
| 6351 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6352 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6353 | if (mService != null) { |
| 6354 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6355 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6356 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6357 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | return null; |
| 6362 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6363 | |
| 6364 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6365 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6366 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6367 | * 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] | 6368 | * 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] | 6369 | * package list results in locked tasks belonging to those packages to be finished. |
| 6370 | * <p> |
| 6371 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6372 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages |
| 6373 | * set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6374 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6375 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6376 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6377 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6378 | * an affiliated user or profile. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6379 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6380 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6381 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6382 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6383 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6384 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6385 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6386 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6387 | if (mService != null) { |
| 6388 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6389 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6390 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6391 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6392 | } |
| 6393 | } |
| 6394 | } |
| 6395 | |
| 6396 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6397 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6398 | * |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6399 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6400 | * an affiliated user or profile. |
| 6401 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6402 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6403 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6404 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6405 | if (mService != null) { |
| 6406 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6407 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6408 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6409 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6410 | } |
| 6411 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6412 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6413 | } |
| 6414 | |
| 6415 | /** |
| 6416 | * This function lets the caller know whether the given component is allowed to start the |
| 6417 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6418 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6419 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6420 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6421 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6422 | if (mService != null) { |
| 6423 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6424 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6425 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6426 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6427 | } |
| 6428 | } |
| 6429 | return false; |
| 6430 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6431 | |
| 6432 | /** |
| 6433 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 6434 | * 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] | 6435 | * <p> |
| 6436 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6437 | * <ul> |
| 6438 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 6439 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 6440 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6441 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6442 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6443 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6444 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 6445 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 6446 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 6447 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 6448 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6449 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6450 | * <p> |
| 6451 | * 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] | 6452 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6453 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 6454 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6455 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6456 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6457 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 6458 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6459 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6460 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 6461 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6462 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6463 | * |
| 6464 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6465 | * @param setting The name of the setting to update. |
| 6466 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6467 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6468 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6469 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6470 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6471 | if (mService != null) { |
| 6472 | try { |
| 6473 | mService.setGlobalSetting(admin, setting, value); |
| 6474 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6475 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6476 | } |
| 6477 | } |
| 6478 | } |
| 6479 | |
| 6480 | /** |
| 6481 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 6482 | * that the value of the setting is in the correct form for the setting type should be performed |
| 6483 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6484 | * <p> |
| 6485 | * 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] | 6486 | * <ul> |
| 6487 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
| 6488 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 6489 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6490 | * <p> |
| 6491 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6492 | * <ul> |
| 6493 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 6494 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6495 | * |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 6496 | * <strong>Note: Starting from Android O, apps should no longer call this method with the |
| 6497 | * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is |
| 6498 | * deprecated. Instead, device owners or profile owners should use the restriction |
| 6499 | * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
| 6500 | * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method |
| 6501 | * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, |
| 6502 | * an {@link UnsupportedOperationException} is thrown. |
| 6503 | * </strong> |
| 6504 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6505 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6506 | * @param setting The name of the setting to update. |
| 6507 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6508 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6509 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6510 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6511 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6512 | if (mService != null) { |
| 6513 | try { |
| 6514 | mService.setSecureSetting(admin, setting, value); |
| 6515 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6516 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6517 | } |
| 6518 | } |
| 6519 | } |
| 6520 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6521 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6522 | * Designates a specific service component as the provider for making permission requests of a |
| 6523 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6524 | * <p/> |
| 6525 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6526 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6527 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6528 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6529 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6530 | * provider previously assigned. |
| 6531 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6532 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6533 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6534 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6535 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6536 | if (mService != null) { |
| 6537 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6538 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6539 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6540 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6541 | } |
| 6542 | } |
| 6543 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6544 | |
| 6545 | /** |
| 6546 | * 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] | 6547 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6548 | * |
| 6549 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6550 | * @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] | 6551 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6552 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6553 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6554 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6555 | if (mService != null) { |
| 6556 | try { |
| 6557 | mService.setMasterVolumeMuted(admin, on); |
| 6558 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6559 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6560 | } |
| 6561 | } |
| 6562 | } |
| 6563 | |
| 6564 | /** |
| 6565 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6566 | * |
| 6567 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6568 | * @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] | 6569 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6570 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6571 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6572 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6573 | if (mService != null) { |
| 6574 | try { |
| 6575 | return mService.isMasterVolumeMuted(admin); |
| 6576 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6577 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6578 | } |
| 6579 | } |
| 6580 | return false; |
| 6581 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6582 | |
| 6583 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6584 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6585 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6586 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6587 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6588 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6589 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6590 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6591 | * @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] | 6592 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6593 | * @see #setDelegatedScopes |
| 6594 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6595 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6596 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6597 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6598 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6599 | if (mService != null) { |
| 6600 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6601 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6602 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6603 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6604 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6605 | } |
| 6606 | } |
| 6607 | } |
| 6608 | |
| 6609 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6610 | * 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] | 6611 | * 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] | 6612 | * <p> |
| 6613 | * <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] | 6614 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6615 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6616 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6617 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6618 | * @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] | 6619 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6620 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6621 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6622 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6623 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6624 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6625 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6626 | if (mService != null) { |
| 6627 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6628 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6629 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6630 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6631 | } |
| 6632 | } |
| 6633 | return false; |
| 6634 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6635 | |
| 6636 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6637 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6638 | * package to be available in the parent profile. As a result the user will be able to add |
| 6639 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6640 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6641 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6642 | * <p> |
| 6643 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6644 | * |
| 6645 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6646 | * @param packageName The package from which widget providers are white-listed. |
| 6647 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6648 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6649 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6650 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6651 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6652 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6653 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6654 | if (mService != null) { |
| 6655 | try { |
| 6656 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6657 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6658 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6659 | } |
| 6660 | } |
| 6661 | return false; |
| 6662 | } |
| 6663 | |
| 6664 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6665 | * 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] | 6666 | * package to be available in the parent profile. For this method to take effect the package |
| 6667 | * should have been added via |
| 6668 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6669 | * <p> |
| 6670 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6671 | * |
| 6672 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6673 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6674 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6675 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6676 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6677 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6678 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6679 | public boolean removeCrossProfileWidgetProvider( |
| 6680 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6681 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6682 | if (mService != null) { |
| 6683 | try { |
| 6684 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6685 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6686 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6687 | } |
| 6688 | } |
| 6689 | return false; |
| 6690 | } |
| 6691 | |
| 6692 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6693 | * 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] | 6694 | * available in the parent profile. |
| 6695 | * |
| 6696 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6697 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6698 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6699 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6700 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6701 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6702 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6703 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6704 | if (mService != null) { |
| 6705 | try { |
| 6706 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6707 | if (providers != null) { |
| 6708 | return providers; |
| 6709 | } |
| 6710 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6711 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6712 | } |
| 6713 | } |
| 6714 | return Collections.emptyList(); |
| 6715 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6716 | |
| 6717 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6718 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6719 | * |
| 6720 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6721 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6722 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6723 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6724 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6725 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6726 | try { |
| 6727 | mService.setUserIcon(admin, icon); |
| 6728 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6729 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6730 | } |
| 6731 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6732 | |
| 6733 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6734 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6735 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6736 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6737 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6738 | * components in the device owner package can set system update policies and the most |
| 6739 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6740 | * @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] | 6741 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6742 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6743 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6744 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6745 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6746 | if (mService != null) { |
| 6747 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6748 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6749 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6750 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6751 | } |
| 6752 | } |
| 6753 | } |
| 6754 | |
| 6755 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6756 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6757 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6758 | * @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] | 6759 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6760 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6761 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6762 | if (mService != null) { |
| 6763 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6764 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6765 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6766 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6767 | } |
| 6768 | } |
| 6769 | return null; |
| 6770 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6771 | |
| 6772 | /** |
| 6773 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6774 | * <p> |
| 6775 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6776 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6777 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6778 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6779 | * |
| 6780 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6781 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6782 | * @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] | 6783 | * place. {@code true} otherwise. |
| 6784 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6785 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6786 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6787 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6788 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6789 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6790 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6791 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6792 | } |
| 6793 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6794 | |
| 6795 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6796 | * 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] | 6797 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6798 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6799 | * |
| 6800 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6801 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6802 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6803 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6804 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6805 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6806 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6807 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6808 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6809 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6810 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6811 | } |
| 6812 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6813 | |
| 6814 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6815 | * Called by the system update service to notify device and profile owners of pending system |
| 6816 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6817 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6818 | * 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] | 6819 | * update is a security patch. Otherwise, use |
| 6820 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 6821 | * |
| 6822 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6823 | * indicating when the current pending update was first available. {@code -1} if no |
| 6824 | * update is available. |
| 6825 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6826 | * @hide |
| 6827 | */ |
| 6828 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6829 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6830 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6831 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6832 | if (mService != null) { |
| 6833 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6834 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 6835 | } catch (RemoteException re) { |
| 6836 | throw re.rethrowFromSystemServer(); |
| 6837 | } |
| 6838 | } |
| 6839 | } |
| 6840 | |
| 6841 | /** |
| 6842 | * Called by the system update service to notify device and profile owners of pending system |
| 6843 | * updates. |
| 6844 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6845 | * This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6846 | * when it is known whether the pending system update is a security patch. |
| 6847 | * |
| 6848 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6849 | * indicating when the current pending update was first available. {@code -1} if no |
| 6850 | * update is available. |
| 6851 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 6852 | * {@code false} if not. |
| 6853 | * @see #notifyPendingSystemUpdate(long) |
| 6854 | * @hide |
| 6855 | */ |
| 6856 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6857 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6858 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 6859 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 6860 | if (mService != null) { |
| 6861 | try { |
| 6862 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 6863 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6864 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6865 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6866 | } |
| 6867 | } |
| 6868 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6869 | |
| 6870 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 6871 | * Called by device or profile owners to get information about a pending system update. |
| 6872 | * |
| 6873 | * @param admin Which profile or device owner this request is associated with. |
| 6874 | * @return Information about a pending system update or {@code null} if no update pending. |
| 6875 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 6876 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 6877 | */ |
| 6878 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 6879 | throwIfParentInstance("getPendingSystemUpdate"); |
| 6880 | try { |
| 6881 | return mService.getPendingSystemUpdate(admin); |
| 6882 | } catch (RemoteException re) { |
| 6883 | throw re.rethrowFromSystemServer(); |
| 6884 | } |
| 6885 | } |
| 6886 | |
| 6887 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6888 | * Set the default response for future runtime permission requests by applications. This |
| 6889 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6890 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 6891 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 6892 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 6893 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 6894 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 6895 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6896 | * <p/> |
| 6897 | * 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] | 6898 | * 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] | 6899 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6900 | * @param admin Which profile or device owner this request is associated with. |
| 6901 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6902 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6903 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6904 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6905 | * @see #setDelegatedScopes |
| 6906 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6907 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6908 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6909 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6910 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6911 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6912 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6913 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | /** |
| 6918 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6919 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6920 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6921 | * @param admin Which profile or device owner this request is associated with. |
| 6922 | * @return the current policy for future permission requests. |
| 6923 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6924 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6925 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6926 | try { |
| 6927 | return mService.getPermissionPolicy(admin); |
| 6928 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6929 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6930 | } |
| 6931 | } |
| 6932 | |
| 6933 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6934 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6935 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6936 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6937 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6938 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6939 | * 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] | 6940 | * by a profile owner, device owner, or a delegate given the |
| 6941 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6942 | * <p/> |
| 6943 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6944 | * the permission. It retains the previous grant, if any. |
| 6945 | * <p/> |
| 6946 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6947 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6948 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6949 | * @param admin Which profile or device owner this request is associated with. |
| 6950 | * @param packageName The application to grant or revoke a permission to. |
| 6951 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6952 | * @param grantState The permission grant state which is one of |
| 6953 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6954 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6955 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6956 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6957 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6958 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6959 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6960 | * @see #setDelegatedScopes |
| 6961 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6962 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6963 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6964 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6965 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6966 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6967 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6968 | permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6969 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6970 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6971 | } |
| 6972 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6973 | |
| 6974 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6975 | * Returns the current grant state of a runtime permission for a specific application. This |
| 6976 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6977 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6978 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6979 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 6980 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6981 | * @param packageName The application to check the grant state for. |
| 6982 | * @param permission The permission to check for. |
| 6983 | * @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] | 6984 | * has not set a grant state, the return value is |
| 6985 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6986 | * permission is currently granted for the package. |
| 6987 | * <p/> |
| 6988 | * If a grant state was set by the profile or device owner, then the return value will |
| 6989 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6990 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6991 | * currently denied or granted. |
| 6992 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6993 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6994 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6995 | * @see #setDelegatedScopes |
| 6996 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6997 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 6998 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6999 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7000 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7001 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7002 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 7003 | permission); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7004 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7005 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7006 | } |
| 7007 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7008 | |
| 7009 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7010 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 7011 | * or device, setting itself as the device or profile owner. |
| 7012 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7013 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 7014 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7015 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7016 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 7017 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7018 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7019 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7020 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7021 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7022 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7023 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7024 | } |
| 7025 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7026 | |
| 7027 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7028 | * Checks whether it is possible to initiate provisioning a managed device, |
| 7029 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7030 | * |
| 7031 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 7032 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 7033 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 7034 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7035 | * @param packageName The package of the component that would be set as device, user, or profile |
| 7036 | * owner. |
| 7037 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7038 | * @hide |
| 7039 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7040 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 7041 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7042 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7043 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7044 | } catch (RemoteException re) { |
| 7045 | throw re.rethrowFromSystemServer(); |
| 7046 | } |
| 7047 | } |
| 7048 | |
| 7049 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7050 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 7051 | * 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] | 7052 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7053 | * @param admin Which profile owner this request is associated with. |
| 7054 | * @return if this user is a managed profile of another user. |
| 7055 | */ |
| 7056 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7057 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7058 | try { |
| 7059 | return mService.isManagedProfile(admin); |
| 7060 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7061 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7062 | } |
| 7063 | } |
| 7064 | |
| 7065 | /** |
| 7066 | * @hide |
| 7067 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 7068 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 7069 | * @param admin Which device owner this request is associated with. |
| 7070 | * @return if this user is a system-only user. |
| 7071 | */ |
| 7072 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 7073 | try { |
| 7074 | return mService.isSystemOnlyUser(admin); |
| 7075 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7076 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7077 | } |
| 7078 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7079 | |
| 7080 | /** |
| 7081 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 7082 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7083 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7084 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 7085 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 7086 | * <p> |
| 7087 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 7088 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7089 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7090 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7091 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7092 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7093 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7094 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7095 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7096 | } |
| 7097 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7098 | |
| 7099 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7100 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 7101 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7102 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7103 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7104 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7105 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7106 | */ |
| 7107 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7108 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7109 | try { |
| 7110 | mService.reboot(admin); |
| 7111 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7112 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7113 | } |
| 7114 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7115 | |
| 7116 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7117 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 7118 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 7119 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 7120 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 7121 | * truncated. |
| 7122 | * <p> |
| 7123 | * 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] | 7124 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7125 | * and set a new version of this string accordingly. |
| 7126 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7127 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7128 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7129 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 7130 | * existing message. |
| 7131 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7132 | */ |
| 7133 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7134 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7135 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7136 | if (mService != null) { |
| 7137 | try { |
| 7138 | mService.setShortSupportMessage(admin, message); |
| 7139 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7140 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7141 | } |
| 7142 | } |
| 7143 | } |
| 7144 | |
| 7145 | /** |
| 7146 | * Called by a device admin to get the short support message. |
| 7147 | * |
| 7148 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7149 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 7150 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7151 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7152 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7153 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7154 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7155 | if (mService != null) { |
| 7156 | try { |
| 7157 | return mService.getShortSupportMessage(admin); |
| 7158 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7159 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7160 | } |
| 7161 | } |
| 7162 | return null; |
| 7163 | } |
| 7164 | |
| 7165 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7166 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 7167 | * in the device administators settings screen. |
| 7168 | * <p> |
| 7169 | * 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] | 7170 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7171 | * and set a new version of this string accordingly. |
| 7172 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7173 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7174 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7175 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 7176 | * existing message. |
| 7177 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7178 | */ |
| 7179 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7180 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7181 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7182 | if (mService != null) { |
| 7183 | try { |
| 7184 | mService.setLongSupportMessage(admin, message); |
| 7185 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7186 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7187 | } |
| 7188 | } |
| 7189 | } |
| 7190 | |
| 7191 | /** |
| 7192 | * Called by a device admin to get the long support message. |
| 7193 | * |
| 7194 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7195 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 7196 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7197 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7198 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7199 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7200 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7201 | if (mService != null) { |
| 7202 | try { |
| 7203 | return mService.getLongSupportMessage(admin); |
| 7204 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7205 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7206 | } |
| 7207 | } |
| 7208 | return null; |
| 7209 | } |
| 7210 | |
| 7211 | /** |
| 7212 | * Called by the system to get the short support message. |
| 7213 | * |
| 7214 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7215 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7216 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7217 | * |
| 7218 | * @hide |
| 7219 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7220 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7221 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7222 | if (mService != null) { |
| 7223 | try { |
| 7224 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 7225 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7226 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7227 | } |
| 7228 | } |
| 7229 | return null; |
| 7230 | } |
| 7231 | |
| 7232 | |
| 7233 | /** |
| 7234 | * Called by the system to get the long support message. |
| 7235 | * |
| 7236 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7237 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7238 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7239 | * |
| 7240 | * @hide |
| 7241 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7242 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 7243 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7244 | if (mService != null) { |
| 7245 | try { |
| 7246 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 7247 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7248 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7249 | } |
| 7250 | } |
| 7251 | return null; |
| 7252 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7253 | |
| 7254 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 7255 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 7256 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7257 | * |
| 7258 | * <p>The following methods are supported for the parent instance, all other methods will |
| 7259 | * throw a SecurityException when called on the parent instance: |
| 7260 | * <ul> |
| 7261 | * <li>{@link #getPasswordQuality}</li> |
| 7262 | * <li>{@link #setPasswordQuality}</li> |
| 7263 | * <li>{@link #getPasswordMinimumLength}</li> |
| 7264 | * <li>{@link #setPasswordMinimumLength}</li> |
| 7265 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 7266 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 7267 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 7268 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 7269 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 7270 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 7271 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 7272 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 7273 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 7274 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 7275 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 7276 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 7277 | * <li>{@link #getPasswordHistoryLength}</li> |
| 7278 | * <li>{@link #setPasswordHistoryLength}</li> |
| 7279 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 7280 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 7281 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 7282 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7283 | * <li>{@link #isActivePasswordSufficient}</li> |
| 7284 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 7285 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 7286 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 7287 | * <li>{@link #getMaximumTimeToLock}</li> |
| 7288 | * <li>{@link #setMaximumTimeToLock}</li> |
| 7289 | * <li>{@link #lockNow}</li> |
| 7290 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 7291 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 7292 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 7293 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 7294 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 7295 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7296 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7297 | * |
| 7298 | * @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] | 7299 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7300 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7301 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7302 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7303 | try { |
| 7304 | if (!mService.isManagedProfile(admin)) { |
| 7305 | throw new SecurityException("The current user does not have a parent profile."); |
| 7306 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7307 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7308 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7309 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7310 | } |
| 7311 | } |
| 7312 | |
| 7313 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7314 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7315 | * |
| 7316 | * <p> Security logs contain various information intended for security auditing purposes. |
| 7317 | * See {@link SecurityEvent} for details. |
| 7318 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7319 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 7320 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7321 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7322 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7323 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7324 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7325 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7326 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7327 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7328 | * @see #retrieveSecurityLogs |
| 7329 | */ |
| 7330 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7331 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7332 | try { |
| 7333 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 7334 | } catch (RemoteException re) { |
| 7335 | throw re.rethrowFromSystemServer(); |
| 7336 | } |
| 7337 | } |
| 7338 | |
| 7339 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7340 | * Return whether security logging is enabled or not by the device owner. |
| 7341 | * |
| 7342 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 7343 | * thrown. |
| 7344 | * |
| 7345 | * @param admin Which device owner this request is associated with. |
| 7346 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 7347 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7348 | */ |
Bartosz Fabianowski | 0ec0000 | 2017-03-24 14:22:24 +0100 | [diff] [blame] | 7349 | public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7350 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7351 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7352 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7353 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7354 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7355 | } |
| 7356 | } |
| 7357 | |
| 7358 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7359 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 7360 | * this API after device boots. |
| 7361 | * |
| 7362 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 7363 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 7364 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7365 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7366 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7367 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7368 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7369 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7370 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 7371 | * 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] | 7372 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7373 | * profile or secondary user that is not affiliated with the device owner user. |
| 7374 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7375 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7376 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7377 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7378 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7379 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7380 | if (list != null) { |
| 7381 | return list.getList(); |
| 7382 | } else { |
| 7383 | // Rate limit exceeded. |
| 7384 | return null; |
| 7385 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7386 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7387 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7388 | } |
| 7389 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7390 | |
| 7391 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7392 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7393 | * profile. |
| 7394 | * |
| 7395 | * @hide |
| 7396 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7397 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7398 | mContext.checkSelfPermission( |
| 7399 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7400 | if (!uInfo.isManagedProfile()) { |
| 7401 | throw new SecurityException("The user " + uInfo.id |
| 7402 | + " does not have a parent profile."); |
| 7403 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7404 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7408 | * 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] | 7409 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7410 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7411 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7412 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7413 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7414 | * |
| 7415 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7416 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7417 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7418 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7419 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7420 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7421 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7422 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7423 | * profile or secondary user that is not affiliated with the device owner user. |
| 7424 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7425 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7426 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7427 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7428 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7429 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7430 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7431 | if (list != null) { |
| 7432 | return list.getList(); |
| 7433 | } else { |
| 7434 | return null; |
| 7435 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7436 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7437 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7438 | } |
| 7439 | } |
| 7440 | |
| 7441 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7442 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7443 | * 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] | 7444 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7445 | * <p> |
| 7446 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7447 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7448 | * |
| 7449 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7450 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7451 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7452 | */ |
| 7453 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7454 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7455 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7456 | // always enforce alpha channel to have 100% opacity |
| 7457 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7458 | mService.setOrganizationColor(admin, color); |
| 7459 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7460 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7461 | } |
| 7462 | } |
| 7463 | |
| 7464 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7465 | * @hide |
| 7466 | * |
| 7467 | * Sets the color used for customization. |
| 7468 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7469 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7470 | * @param userId which user to set the color to. |
| 7471 | * @RequiresPermission(allOf = { |
| 7472 | * Manifest.permission.MANAGE_USERS, |
| 7473 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7474 | */ |
| 7475 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7476 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7477 | // always enforce alpha channel to have 100% opacity |
| 7478 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7479 | mService.setOrganizationColorForUser(color, userId); |
| 7480 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7481 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7482 | } |
| 7483 | } |
| 7484 | |
| 7485 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7486 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7487 | * This color is used as background color of the confirm credentials screen for that user. |
| 7488 | * |
| 7489 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7490 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7491 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7492 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7493 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7494 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7495 | try { |
| 7496 | return mService.getOrganizationColor(admin); |
| 7497 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7498 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7499 | } |
| 7500 | } |
| 7501 | |
| 7502 | /** |
| 7503 | * @hide |
| 7504 | * Retrieve the customization color for a given user. |
| 7505 | * |
| 7506 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7507 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7508 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7509 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7510 | try { |
| 7511 | return mService.getOrganizationColorForUser(userHandle); |
| 7512 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7513 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7514 | } |
| 7515 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7516 | |
| 7517 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7518 | * 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] | 7519 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7520 | * <p> |
| 7521 | * 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] | 7522 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7523 | * and set a new version of this string accordingly. |
| 7524 | * |
| 7525 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7526 | * @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] | 7527 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7528 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7529 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7530 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7531 | try { |
| 7532 | mService.setOrganizationName(admin, title); |
| 7533 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7534 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7535 | } |
| 7536 | } |
| 7537 | |
| 7538 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7539 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7540 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7541 | * |
| 7542 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7543 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7544 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7545 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7546 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7547 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7548 | try { |
| 7549 | return mService.getOrganizationName(admin); |
| 7550 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7551 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7552 | } |
| 7553 | } |
| 7554 | |
| 7555 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7556 | * Called by the system to retrieve the name of the organization managing the device. |
| 7557 | * |
| 7558 | * @return The organization name or {@code null} if none is set. |
| 7559 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7560 | * MANAGE_USERS permission and is not the system. |
| 7561 | * |
| 7562 | * @hide |
| 7563 | */ |
| 7564 | @SystemApi |
| 7565 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 7566 | @SuppressLint("Doclava125") |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7567 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7568 | try { |
| 7569 | return mService.getDeviceOwnerOrganizationName(); |
| 7570 | } catch (RemoteException re) { |
| 7571 | throw re.rethrowFromSystemServer(); |
| 7572 | } |
| 7573 | } |
| 7574 | |
| 7575 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7576 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7577 | * |
| 7578 | * @param userHandle The user id of the user we're interested in. |
| 7579 | * @return The organization name or {@code null} if none is set. |
| 7580 | * |
| 7581 | * @hide |
| 7582 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7583 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7584 | try { |
| 7585 | return mService.getOrganizationNameForUser(userHandle); |
| 7586 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7587 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7592 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7593 | * return {@link #STATE_USER_UNMANAGED} |
| 7594 | * @hide |
| 7595 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7596 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7597 | @UserProvisioningState |
| 7598 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7599 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7600 | if (mService != null) { |
| 7601 | try { |
| 7602 | return mService.getUserProvisioningState(); |
| 7603 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7604 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7605 | } |
| 7606 | } |
| 7607 | return STATE_USER_UNMANAGED; |
| 7608 | } |
| 7609 | |
| 7610 | /** |
| 7611 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7612 | * |
| 7613 | * @param state to store |
| 7614 | * @param userHandle for user |
| 7615 | * @hide |
| 7616 | */ |
| 7617 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7618 | if (mService != null) { |
| 7619 | try { |
| 7620 | mService.setUserProvisioningState(state, userHandle); |
| 7621 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7622 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7623 | } |
| 7624 | } |
| 7625 | } |
| 7626 | |
| 7627 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7628 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7629 | * 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] | 7630 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7631 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7632 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7633 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7634 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7635 | * created. |
| 7636 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7637 | * @param admin Which profile or device owner this request is associated with. |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7638 | * @param ids A set of opaque non-empty affiliation ids. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7639 | * |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7640 | * @throws IllegalArgumentException if {@code ids} is null or contains an empty string. |
| 7641 | */ |
| 7642 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) { |
| 7643 | throwIfParentInstance("setAffiliationIds"); |
| 7644 | if (ids == null) { |
| 7645 | throw new IllegalArgumentException("ids must not be null"); |
| 7646 | } |
| 7647 | try { |
| 7648 | mService.setAffiliationIds(admin, new ArrayList<>(ids)); |
| 7649 | } catch (RemoteException e) { |
| 7650 | throw e.rethrowFromSystemServer(); |
| 7651 | } |
| 7652 | } |
| 7653 | |
| 7654 | /** |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7655 | * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7656 | * empty set if none have been set. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7657 | */ |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7658 | public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) { |
Tony Mak | 62cf586 | 2017-05-02 13:50:18 +0100 | [diff] [blame] | 7659 | throwIfParentInstance("getAffiliationIds"); |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7660 | try { |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7661 | return new ArraySet<>(mService.getAffiliationIds(admin)); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7662 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7663 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7664 | } |
| 7665 | } |
| 7666 | |
| 7667 | /** |
| 7668 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7669 | * Returns whether this user/profile is affiliated with the device. |
| 7670 | * <p> |
| 7671 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7672 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7673 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7674 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7675 | */ |
| 7676 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7677 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7678 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7679 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7680 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7681 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7682 | } |
| 7683 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7684 | |
| 7685 | /** |
| 7686 | * @hide |
| 7687 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7688 | * to be started |
| 7689 | * @param packageName the package to check for |
| 7690 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7691 | */ |
| 7692 | public boolean isUninstallInQueue(String packageName) { |
| 7693 | try { |
| 7694 | return mService.isUninstallInQueue(packageName); |
| 7695 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7696 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7697 | } |
| 7698 | } |
| 7699 | |
| 7700 | /** |
| 7701 | * @hide |
| 7702 | * @param packageName the package containing active DAs to be uninstalled |
| 7703 | */ |
| 7704 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7705 | try { |
| 7706 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7707 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7708 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7709 | } |
| 7710 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7711 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7712 | /** |
| 7713 | * @hide |
| 7714 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7715 | * If the admin is a profile owner or device owner it will still be removed. |
| 7716 | * |
| 7717 | * @param userHandle user id to remove the admin for. |
| 7718 | * @param admin The administration compononent to remove. |
| 7719 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7720 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7721 | */ |
| 7722 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7723 | try { |
| 7724 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7725 | } catch (RemoteException re) { |
| 7726 | throw re.rethrowFromSystemServer(); |
| 7727 | } |
| 7728 | } |
| 7729 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7730 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7731 | * Returns whether the device has been provisioned. |
| 7732 | * |
| 7733 | * <p>Not for use by third-party applications. |
| 7734 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7735 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7736 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7737 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7738 | public boolean isDeviceProvisioned() { |
| 7739 | try { |
| 7740 | return mService.isDeviceProvisioned(); |
| 7741 | } catch (RemoteException re) { |
| 7742 | throw re.rethrowFromSystemServer(); |
| 7743 | } |
| 7744 | } |
| 7745 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7746 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7747 | * Writes that the provisioning configuration has been applied. |
| 7748 | * |
| 7749 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7750 | * permission. |
| 7751 | * |
| 7752 | * <p>Not for use by third-party applications. |
| 7753 | * |
| 7754 | * @hide |
| 7755 | */ |
| 7756 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7757 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7758 | public void setDeviceProvisioningConfigApplied() { |
| 7759 | try { |
| 7760 | mService.setDeviceProvisioningConfigApplied(); |
| 7761 | } catch (RemoteException re) { |
| 7762 | throw re.rethrowFromSystemServer(); |
| 7763 | } |
| 7764 | } |
| 7765 | |
| 7766 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7767 | * Returns whether the provisioning configuration has been applied. |
| 7768 | * |
| 7769 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7770 | * |
| 7771 | * <p>Not for use by third-party applications. |
| 7772 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7773 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7774 | * |
| 7775 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7776 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7777 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 7778 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7779 | public boolean isDeviceProvisioningConfigApplied() { |
| 7780 | try { |
| 7781 | return mService.isDeviceProvisioningConfigApplied(); |
| 7782 | } catch (RemoteException re) { |
| 7783 | throw re.rethrowFromSystemServer(); |
| 7784 | } |
| 7785 | } |
| 7786 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7787 | /** |
| 7788 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7789 | * Force update user setup completed status. This API has no effect on user build. |
| 7790 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7791 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7792 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7793 | */ |
| 7794 | public void forceUpdateUserSetupComplete() { |
| 7795 | try { |
| 7796 | mService.forceUpdateUserSetupComplete(); |
| 7797 | } catch (RemoteException re) { |
| 7798 | throw re.rethrowFromSystemServer(); |
| 7799 | } |
| 7800 | } |
| 7801 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7802 | private void throwIfParentInstance(String functionName) { |
| 7803 | if (mParentInstance) { |
| 7804 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7805 | } |
| 7806 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7807 | |
| 7808 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7809 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7810 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7811 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 7812 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7813 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7814 | * <p> Backup service is off by default when device owner is present. |
| 7815 | * |
Rubin Xu | 0367f07 | 2017-04-24 20:17:16 +0100 | [diff] [blame] | 7816 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7817 | * @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] | 7818 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7819 | */ |
| 7820 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7821 | throwIfParentInstance("setBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7822 | try { |
| 7823 | mService.setBackupServiceEnabled(admin, enabled); |
| 7824 | } catch (RemoteException re) { |
| 7825 | throw re.rethrowFromSystemServer(); |
| 7826 | } |
| 7827 | } |
| 7828 | |
| 7829 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7830 | * Return whether the backup service is enabled by the device owner. |
| 7831 | * |
| 7832 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 7833 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7834 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7835 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7836 | */ |
| 7837 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7838 | throwIfParentInstance("isBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7839 | try { |
| 7840 | return mService.isBackupServiceEnabled(admin); |
| 7841 | } catch (RemoteException re) { |
| 7842 | throw re.rethrowFromSystemServer(); |
| 7843 | } |
| 7844 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7845 | |
| 7846 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7847 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7848 | * |
Robin Lee | a40a2fb | 2017-02-08 17:07:06 +0000 | [diff] [blame] | 7849 | * <p> Network logs contain DNS lookup and connect() library call events. The following library |
| 7850 | * functions are recorded while network logging is active: |
| 7851 | * <ul> |
| 7852 | * <li>{@code getaddrinfo()}</li> |
| 7853 | * <li>{@code gethostbyname()}</li> |
| 7854 | * <li>{@code connect()}</li> |
| 7855 | * </ul> |
| 7856 | * |
| 7857 | * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use |
| 7858 | * full system call logging; event reporting is enabled by default for all processes but not |
| 7859 | * strongly enforced. |
| 7860 | * Events from applications using alternative implementations of libc, making direct kernel |
| 7861 | * calls, or deliberately obfuscating traffic may not be recorded. |
| 7862 | * |
| 7863 | * <p> Some common network events may not be reported. For example: |
| 7864 | * <ul> |
| 7865 | * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use |
| 7866 | * an alternative system for name resolution, and so avoid calling |
| 7867 | * {@code getaddrinfo()} or {@code gethostbyname}.</li> |
| 7868 | * <li>Applications may use datagram sockets for performance reasons, for example |
| 7869 | * for a game client. Calling {@code connect()} is unnecessary for this kind of |
| 7870 | * socket, so it will not trigger a network event.</li> |
| 7871 | * </ul> |
| 7872 | * |
| 7873 | * <p> It is possible to directly intercept layer 3 traffic leaving the device using an |
| 7874 | * always-on VPN service. |
| 7875 | * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} |
| 7876 | * and {@link android.net.VpnService} for details. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7877 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7878 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7879 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7880 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7881 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7882 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7883 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7884 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7885 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7886 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7887 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7888 | */ |
| 7889 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7890 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7891 | try { |
| 7892 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7893 | } catch (RemoteException re) { |
| 7894 | throw re.rethrowFromSystemServer(); |
| 7895 | } |
| 7896 | } |
| 7897 | |
| 7898 | /** |
| 7899 | * Return whether network logging is enabled by a device owner. |
| 7900 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7901 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7902 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7903 | * @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] | 7904 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7905 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7906 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7907 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7908 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7909 | try { |
| 7910 | return mService.isNetworkLoggingEnabled(admin); |
| 7911 | } catch (RemoteException re) { |
| 7912 | throw re.rethrowFromSystemServer(); |
| 7913 | } |
| 7914 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7915 | |
| 7916 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7917 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7918 | * A device owner has to provide a batchToken provided as part of |
| 7919 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7920 | * 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] | 7921 | * |
| 7922 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7923 | * |
| 7924 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7925 | * |
| 7926 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7927 | * after the device device owner has been notified via |
| 7928 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7929 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7930 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7931 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7932 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7933 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7934 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7935 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7936 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7937 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7938 | * @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] | 7939 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7940 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7941 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7942 | * 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] | 7943 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7944 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7945 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7946 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7947 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7948 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7949 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7950 | } catch (RemoteException re) { |
| 7951 | throw re.rethrowFromSystemServer(); |
| 7952 | } |
| 7953 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7954 | |
| 7955 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7956 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 7957 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7958 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7959 | * <p> |
Tony Mak | eda0a9a | 2017-04-25 12:07:14 +0100 | [diff] [blame] | 7960 | * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
| 7961 | * Note that the {@link Context} used to obtain this |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7962 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7963 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7964 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7965 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7966 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7967 | * explicit component name or a package name to match an |
| 7968 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7969 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7970 | * 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] | 7971 | * @param flags Operation options for the binding operation. See |
| 7972 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7973 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7974 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7975 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7976 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7977 | * {@code false} is returned if the connection is not made and you will not |
| 7978 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7979 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7980 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7981 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7982 | */ |
| 7983 | public boolean bindDeviceAdminServiceAsUser( |
| 7984 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7985 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7986 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7987 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7988 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7989 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 7990 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7991 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7992 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7993 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7994 | sd, flags, targetUser.getIdentifier()); |
| 7995 | } catch (RemoteException re) { |
| 7996 | throw re.rethrowFromSystemServer(); |
| 7997 | } |
| 7998 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7999 | |
| 8000 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8001 | * Returns the list of target users that the calling device or profile owner can use when |
| 8002 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 8003 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 8004 | * 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] | 8005 | * <ul> |
| 8006 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 8007 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8008 | * </ul> |
| 8009 | */ |
| 8010 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 8011 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 8012 | try { |
| 8013 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 8014 | } catch (RemoteException re) { |
| 8015 | throw re.rethrowFromSystemServer(); |
| 8016 | } |
| 8017 | } |
| 8018 | |
| 8019 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8020 | * Called by the system to get the time at which the device owner last retrieved security |
| 8021 | * logging entries. |
| 8022 | * |
| 8023 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 8024 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8025 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8026 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8027 | * |
| 8028 | * @hide |
| 8029 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8030 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8031 | public long getLastSecurityLogRetrievalTime() { |
| 8032 | try { |
| 8033 | return mService.getLastSecurityLogRetrievalTime(); |
| 8034 | } catch (RemoteException re) { |
| 8035 | throw re.rethrowFromSystemServer(); |
| 8036 | } |
| 8037 | } |
| 8038 | |
| 8039 | /** |
| 8040 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 8041 | * |
| 8042 | * @return the time at which the device owner most recently requested a bug report, in |
| 8043 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8044 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8045 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8046 | * |
| 8047 | * @hide |
| 8048 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8049 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8050 | public long getLastBugReportRequestTime() { |
| 8051 | try { |
| 8052 | return mService.getLastBugReportRequestTime(); |
| 8053 | } catch (RemoteException re) { |
| 8054 | throw re.rethrowFromSystemServer(); |
| 8055 | } |
| 8056 | } |
| 8057 | |
| 8058 | /** |
| 8059 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 8060 | * events. |
| 8061 | * |
| 8062 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 8063 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8064 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8065 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8066 | * |
| 8067 | * @hide |
| 8068 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8069 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8070 | public long getLastNetworkLogRetrievalTime() { |
| 8071 | try { |
| 8072 | return mService.getLastNetworkLogRetrievalTime(); |
| 8073 | } catch (RemoteException re) { |
| 8074 | throw re.rethrowFromSystemServer(); |
| 8075 | } |
| 8076 | } |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8077 | |
| 8078 | /** |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8079 | * Called by the system to find out whether the current user's IME was set by the device/profile |
| 8080 | * owner or the user. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8081 | * |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8082 | * @return {@code true} if the user's IME was set by the device or profile owner, {@code false} |
| 8083 | * otherwise. |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8084 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8085 | * |
| 8086 | * @hide |
| 8087 | */ |
| 8088 | @TestApi |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8089 | public boolean isCurrentInputMethodSetByOwner() { |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8090 | try { |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8091 | return mService.isCurrentInputMethodSetByOwner(); |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8092 | } catch (RemoteException re) { |
| 8093 | throw re.rethrowFromSystemServer(); |
| 8094 | } |
| 8095 | } |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8096 | |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8097 | /** |
| 8098 | * Called by the system to get a list of CA certificates that were installed by the device or |
| 8099 | * profile owner. |
| 8100 | * |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8101 | * <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] | 8102 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 8103 | * |
| 8104 | * @param user The user for whom to retrieve information. |
| 8105 | * @return list of aliases identifying CA certificates installed by the device or profile owner |
| 8106 | * @throws SecurityException if the caller does not have permission to retrieve information |
| 8107 | * about the given user's CA certificates. |
| 8108 | * |
| 8109 | * @hide |
| 8110 | */ |
| 8111 | @TestApi |
| 8112 | public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) { |
| 8113 | try { |
| 8114 | return mService.getOwnerInstalledCaCerts(user).getList(); |
| 8115 | } catch (RemoteException re) { |
| 8116 | throw re.rethrowFromSystemServer(); |
| 8117 | } |
| 8118 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 8119 | } |