Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
| 25 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 26 | import android.annotation.SystemApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 27 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 28 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 29 | import android.app.Activity; |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 30 | import android.app.admin.PasswordMetrics; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 31 | import android.app.IServiceConnection; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 32 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 33 | import android.content.ComponentName; |
| 34 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 35 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 36 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 37 | import android.content.ServiceConnection; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 38 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 39 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 40 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 41 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 42 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 43 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 44 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 45 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 46 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 47 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 48 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 51 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 52 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 53 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 54 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 55 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 56 | import android.telephony.TelephonyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 57 | import android.util.Log; |
| 58 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 59 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 60 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 61 | |
| 62 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 63 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 64 | import java.lang.annotation.Retention; |
| 65 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 66 | import java.net.InetSocketAddress; |
| 67 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 68 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 69 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 70 | import java.security.PrivateKey; |
| 71 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 72 | import java.security.cert.CertificateException; |
| 73 | import java.security.cert.CertificateFactory; |
| 74 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 75 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 76 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 77 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 78 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 79 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 80 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 83 | * 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] | 84 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 85 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 86 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 87 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 88 | * application calling an api may only pass as an argument a device administrator component it |
| 89 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 90 | * <div class="special reference"> |
| 91 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 92 | * <p> |
| 93 | * For more information about managing policies for device administration, read the <a href= |
| 94 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 95 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 96 | */ |
| 97 | public class DevicePolicyManager { |
| 98 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 99 | |
| 100 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 101 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 102 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 103 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 104 | /** @hide */ |
| 105 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 106 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 109 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 110 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 111 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 112 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 113 | mContext = context; |
| 114 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 115 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | /** @hide test will override it. */ |
| 119 | @VisibleForTesting |
| 120 | protected int myUserId() { |
| 121 | return UserHandle.myUserId(); |
| 122 | } |
| 123 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 124 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 125 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 126 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 127 | * <p>A managed profile allows data separation for example for the usage of a |
| 128 | * device as a personal and corporate device. The user which provisioning is started from and |
| 129 | * the managed profile share a launcher. |
| 130 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 131 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 132 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 133 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 134 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 135 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 136 | * {@link #isProvisioningAllowed(String)}. |
| 137 | * |
| 138 | * <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] | 139 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 140 | * 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] | 141 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 142 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 143 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 144 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 145 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 146 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 147 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 148 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 149 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 150 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 152 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 153 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 154 | * <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] | 155 | * in the provisioning intent. The |
| 156 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 157 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 158 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 159 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 160 | * <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] | 161 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 162 | * |
| 163 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 164 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 165 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 166 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 167 | * 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] | 168 | */ |
| 169 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 170 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 171 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 172 | |
| 173 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 174 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 175 | * |
| 176 | * <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] | 177 | * 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] | 178 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 179 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 180 | * allowed. |
| 181 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 182 | * <p>The intent contains the following extras: |
| 183 | * <ul> |
| 184 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 185 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 186 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 187 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 188 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 189 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 190 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 191 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 192 | * |
| 193 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 194 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 195 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 196 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 197 | * 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] | 198 | * |
| 199 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 200 | */ |
| 201 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 202 | public static final String ACTION_PROVISION_MANAGED_USER |
| 203 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 204 | |
| 205 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 206 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 207 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 208 | * |
| 209 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 210 | * A device owner has full control over the device. The device owner can not be modified by the |
| 211 | * user. |
| 212 | * |
| 213 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 214 | * employee or client. |
| 215 | * |
| 216 | * <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] | 217 | * It is possible to check if provisioning is allowed or not by querying the method |
| 218 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 219 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 220 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 221 | * <ul> |
| 222 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 223 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 224 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 225 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 226 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 227 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 228 | * </ul> |
| 229 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 230 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 231 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 232 | * device owner. |
| 233 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 234 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 235 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 236 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 237 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 238 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 239 | * 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] | 240 | */ |
| 241 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 242 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 243 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 244 | |
| 245 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 246 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 247 | * |
| 248 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 249 | * the device. A device owner has full control over the device. The device owner can not be |
| 250 | * modified by the user and the only way of resetting the device is via factory reset. |
| 251 | * |
| 252 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 253 | * employee or client. |
| 254 | * |
| 255 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 256 | * |
| 257 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 258 | * by a privileged app with the permission |
| 259 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 260 | * |
| 261 | * <p>The provisioning intent contains the following properties: |
| 262 | * <ul> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 279 | * |
| 280 | * @hide |
| 281 | */ |
| 282 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 283 | @SystemApi |
| 284 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 285 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 286 | |
| 287 | /** |
| 288 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 289 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 290 | * |
| 291 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 292 | * management state that is distinct from that reached by |
| 293 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 294 | * user, and only has control over device-wide policies, not individual users and their data. |
| 295 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 296 | * this form of device management. |
| 297 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 298 | * <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] | 299 | * A device owner has full control over the device. The device owner can not be modified by the |
| 300 | * user. |
| 301 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 302 | * <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] | 303 | * employee or client. |
| 304 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 305 | * <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] | 306 | * It is possible to check if provisioning is allowed or not by querying the method |
| 307 | * {@link #isProvisioningAllowed(String)}. |
| 308 | * |
| 309 | * <p>The intent contains the following extras: |
| 310 | * <ul> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 312 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 314 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 315 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 316 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 317 | * </ul> |
| 318 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 319 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 320 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 321 | * device owner. |
| 322 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 323 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 324 | * |
| 325 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 326 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 327 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 328 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 329 | * |
| 330 | * @hide |
| 331 | */ |
| 332 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 333 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 334 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 335 | |
| 336 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 337 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 338 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 339 | * <ul> |
| 340 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 341 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 342 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 343 | * </ul> |
| 344 | * |
| 345 | * @hide |
| 346 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 347 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 348 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 349 | public static final String ACTION_PROVISION_FINALIZATION |
| 350 | = "android.app.action.PROVISION_FINALIZATION"; |
| 351 | |
| 352 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 353 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 354 | * |
| 355 | * @hide |
| 356 | */ |
| 357 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 358 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 359 | |
| 360 | /** |
| 361 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 362 | * |
| 363 | * @hide |
| 364 | */ |
| 365 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 366 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 367 | |
| 368 | /** |
| 369 | * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}. |
| 370 | * |
| 371 | * @hide |
| 372 | */ |
| 373 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 374 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 375 | |
| 376 | /** |
| 377 | * Extra for shared bugreport's SHA-256 hash. |
| 378 | * |
| 379 | * @hide |
| 380 | */ |
| 381 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 382 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 383 | |
| 384 | /** |
| 385 | * Extra for remote bugreport notification shown type. |
| 386 | * |
| 387 | * @hide |
| 388 | */ |
| 389 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 390 | "android.app.extra.bugreport_notification_type"; |
| 391 | |
| 392 | /** |
| 393 | * Notification type for a started remote bugreport flow. |
| 394 | * |
| 395 | * @hide |
| 396 | */ |
| 397 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 398 | |
| 399 | /** |
| 400 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 401 | * being taken. |
| 402 | * |
| 403 | * @hide |
| 404 | */ |
| 405 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 406 | |
| 407 | /** |
| 408 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 409 | * |
| 410 | * @hide |
| 411 | */ |
| 412 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 413 | |
| 414 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 415 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 416 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 417 | * |
| 418 | * @hide |
| 419 | */ |
| 420 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 421 | |
| 422 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 423 | * 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] | 424 | * allows a mobile device management application or NFC programmer application which starts |
| 425 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 426 | * <p> |
| 427 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 428 | * sends the intent to pass data to itself on the newly created profile. |
| 429 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 430 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 431 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 432 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 433 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 434 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 435 | * management application after provisioning. |
| 436 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 437 | * <p> |
| 438 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 439 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 440 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 441 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 442 | */ |
| 443 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 444 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 445 | |
| 446 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 447 | * A String extra holding the package name of the mobile device management application that |
| 448 | * will be set as the profile owner or device owner. |
| 449 | * |
| 450 | * <p>If an application starts provisioning directly via an intent with action |
| 451 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 452 | * application that started provisioning. The package will be set as profile owner in that case. |
| 453 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 454 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 455 | * 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] | 456 | * |
| 457 | * <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] | 458 | * 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] | 459 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 460 | * @see DeviceAdminReceiver |
| 461 | * @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] | 462 | * supported, but only if there is only one device admin receiver in the package that requires |
| 463 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 464 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 465 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 466 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 467 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 468 | |
| 469 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 470 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 471 | * application that will be set as the profile owner or device owner and active admin. |
| 472 | * |
| 473 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 474 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 475 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 476 | * 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] | 477 | * |
| 478 | * <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] | 479 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 480 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 481 | * {@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] | 482 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 483 | * |
| 484 | * @see DeviceAdminReceiver |
| 485 | */ |
| 486 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 487 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 488 | |
| 489 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 490 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 491 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 492 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 493 | * |
| 494 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 495 | */ |
| 496 | |
| 497 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 498 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 499 | |
| 500 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 501 | * A String extra that, holds the email address of the account which a managed profile is |
| 502 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 503 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 504 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 505 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 506 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 507 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 508 | * contains this extra, it is forwarded in the |
| 509 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 510 | * device management application that was set as the profile owner during provisioning. |
| 511 | * It is usually used to avoid that the user has to enter their email address twice. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 512 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 513 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 514 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 515 | |
| 516 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 517 | * A integer extra indicating the predominant color to show during the provisioning. |
| 518 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 519 | * |
| 520 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 521 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 522 | */ |
| 523 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 524 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 525 | |
| 526 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 527 | * 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] | 528 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 529 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 530 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 531 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 532 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 533 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 534 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 535 | |
| 536 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 537 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 538 | * will be set to. |
| 539 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 540 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 541 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 542 | */ |
| 543 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 544 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 545 | |
| 546 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 547 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 548 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 549 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 550 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 551 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 552 | */ |
| 553 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 554 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 555 | |
| 556 | /** |
| 557 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 558 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 559 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 560 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 561 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 562 | */ |
| 563 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 564 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 565 | |
| 566 | /** |
| 567 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 568 | * owner provisioning for downloading the mobile device management application. |
| 569 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 570 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 571 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 572 | */ |
| 573 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 574 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 575 | |
| 576 | /** |
| 577 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 578 | * is hidden or not. |
| 579 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 580 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 581 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 582 | */ |
| 583 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 584 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 585 | |
| 586 | /** |
| 587 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 588 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 589 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 590 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 591 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 592 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 593 | */ |
| 594 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 595 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 596 | |
| 597 | /** |
| 598 | * A String extra holding the password of the wifi network in |
| 599 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 600 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 601 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 602 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 603 | */ |
| 604 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 605 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 606 | |
| 607 | /** |
| 608 | * A String extra holding the proxy host for the wifi network in |
| 609 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 610 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 611 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 612 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 613 | */ |
| 614 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 615 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 616 | |
| 617 | /** |
| 618 | * An int extra holding the proxy port for the wifi network in |
| 619 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 620 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 621 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 622 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 623 | */ |
| 624 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 625 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 626 | |
| 627 | /** |
| 628 | * A String extra holding the proxy bypass for the wifi network in |
| 629 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 630 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 631 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 632 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 633 | */ |
| 634 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 635 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 636 | |
| 637 | /** |
| 638 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 639 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 640 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 641 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 642 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 643 | */ |
| 644 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 645 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 646 | |
| 647 | /** |
| 648 | * A String extra holding a url that specifies the download location of the device admin |
| 649 | * package. When not provided it is assumed that the device admin package is already installed. |
| 650 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 651 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 652 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 653 | */ |
| 654 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 655 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 656 | |
| 657 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 658 | * An int extra holding a minimum required version code for the device admin package. If the |
| 659 | * device admin is already installed on the device, it will only be re-downloaded from |
| 660 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 661 | * installed package is less than this version code. |
| 662 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 663 | * <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] | 664 | * provisioning via an NFC bump. |
| 665 | */ |
| 666 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 667 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 668 | |
| 669 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 670 | * A String extra holding a http cookie header which should be used in the http request to the |
| 671 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 672 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 673 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 674 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 675 | */ |
| 676 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 677 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 678 | |
| 679 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 680 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 681 | * the file at download location specified in |
| 682 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 683 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 684 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 685 | * 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] | 686 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 687 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 688 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 689 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 690 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 691 | * |
| 692 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 693 | * 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] | 694 | * 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] | 695 | * 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] | 696 | */ |
| 697 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 698 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 699 | |
| 700 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 701 | * 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] | 702 | * android package archive at the download location specified in {@link |
| 703 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 704 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 705 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 706 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 707 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 708 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 709 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 710 | * 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] | 711 | * the download location. If the checksum does not match an error will be shown to the user and |
| 712 | * the user will be asked to factory reset the device. |
| 713 | * |
| 714 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 715 | * provisioning via an NFC bump. |
| 716 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 717 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 718 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 719 | |
| 720 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 721 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 722 | * has completed successfully. |
| 723 | * |
| 724 | * <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] | 725 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 726 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 727 | * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 728 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 729 | */ |
| 730 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 731 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 732 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 733 | |
| 734 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 735 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 736 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 737 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 738 | * <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] | 739 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 740 | * |
| 741 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 742 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 743 | */ |
| 744 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 745 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 746 | |
| 747 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 748 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 749 | * provisioning. If this extra is not passed, a default image will be shown. |
| 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 responsability of the caller to provide an image with a reasonable |
| 757 | * pixed 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_PROFILE} or |
| 764 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 765 | */ |
| 766 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 767 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 768 | |
| 769 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 770 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 771 | * during setup-wizard. |
| 772 | * |
| 773 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 774 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 775 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 776 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 777 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 778 | * |
| 779 | * @hide |
| 780 | */ |
| 781 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 782 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 783 | |
| 784 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 785 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 786 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 787 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 788 | * A device owner has full control over the device. The device owner can not be modified by the |
| 789 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 790 | * reset. |
| 791 | * |
| 792 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 793 | * employee or client. |
| 794 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 795 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 796 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 797 | * <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] | 798 | * contains the following properties: |
| 799 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 800 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 801 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 802 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 803 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 804 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 805 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 806 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 807 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 808 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 809 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 810 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 811 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 812 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 813 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 814 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 815 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 816 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 817 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 818 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 819 | * 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] | 820 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 821 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 822 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 823 | */ |
| 824 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 825 | = "application/com.android.managedprovisioning"; |
| 826 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 827 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 828 | * Activity action: ask the user to add a new device administrator to the system. |
| 829 | * The desired policy is the ComponentName of the policy in the |
| 830 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 831 | * bring the user through adding the device administrator to the system (or |
| 832 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 833 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 834 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 835 | * field to provide the user with additional explanation (in addition |
| 836 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 837 | * |
| 838 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 839 | * user intervention). However, if your administrator has been updated and is requesting |
| 840 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 841 | * 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] | 842 | */ |
| 843 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 844 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 845 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 846 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 847 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 848 | * @hide |
| 849 | * 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] | 850 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 851 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 852 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 853 | * 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] | 854 | * to remotely control restrictions on the user. |
| 855 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 856 | * <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] | 857 | * result of whether or not the user approved the action. If approved, the result will |
| 858 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 859 | * as a profile owner. |
| 860 | * |
| 861 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 862 | * field to provide the user with additional explanation (in addition |
| 863 | * to your component's description) about what is being added. |
| 864 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 865 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 866 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 867 | */ |
| 868 | @SystemApi |
| 869 | public static final String ACTION_SET_PROFILE_OWNER |
| 870 | = "android.app.action.SET_PROFILE_OWNER"; |
| 871 | |
| 872 | /** |
| 873 | * @hide |
| 874 | * Name of the profile owner admin that controls the user. |
| 875 | */ |
| 876 | @SystemApi |
| 877 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 878 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 879 | |
| 880 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 881 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 882 | * 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] | 883 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 884 | * @hide |
| 885 | */ |
| 886 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 887 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 888 | |
| 889 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 890 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 891 | * |
| 892 | * This broadcast is sent only to the primary user. |
| 893 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 894 | */ |
| 895 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 896 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 897 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 898 | |
| 899 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 900 | * The ComponentName of the administrator component. |
| 901 | * |
| 902 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 903 | */ |
| 904 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 905 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 906 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 907 | * An optional CharSequence providing additional explanation for why the |
| 908 | * admin is being added. |
| 909 | * |
| 910 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 911 | */ |
| 912 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 913 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 914 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 915 | * Activity action: have the user enter a new password. This activity should |
| 916 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 917 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 918 | * enter a new password that meets the current requirements. You can use |
| 919 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 920 | * have the user select a new password in order to meet the current |
| 921 | * constraints. Upon being resumed from this activity, you can check the new |
| 922 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 923 | * |
| 924 | * If the intent is launched from within a managed profile with a profile |
| 925 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 926 | * this will trigger entering a new password for the parent of the profile. |
| 927 | * For all other cases it will trigger entering a new password for the user |
| 928 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 929 | * |
| 930 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 931 | */ |
| 932 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 933 | public static final String ACTION_SET_NEW_PASSWORD |
| 934 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 935 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 936 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 937 | * Activity action: have the user enter a new password for the parent profile. |
| 938 | * If the intent is launched from within a managed profile, this will trigger |
| 939 | * entering a new password for the parent of the profile. In all other cases |
| 940 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 941 | */ |
| 942 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 943 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 944 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 945 | |
| 946 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 947 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 948 | * the parent profile to access intents sent from the managed profile. |
| 949 | * That is, when an app in the managed profile calls |
| 950 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 951 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 952 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 953 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 954 | |
| 955 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 956 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 957 | * the managed profile to access intents sent from the parent profile. |
| 958 | * That is, when an app in the parent profile calls |
| 959 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 960 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 961 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 962 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 963 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 964 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 965 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 966 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 967 | */ |
| 968 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 969 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 970 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 971 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 972 | /** |
| 973 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 974 | * Already granted or denied permissions are not affected by this. |
| 975 | */ |
| 976 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 977 | |
| 978 | /** |
| 979 | * Permission policy to always grant new permission requests for runtime permissions. |
| 980 | * Already granted or denied permissions are not affected by this. |
| 981 | */ |
| 982 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 983 | |
| 984 | /** |
| 985 | * Permission policy to always deny new permission requests for runtime permissions. |
| 986 | * Already granted or denied permissions are not affected by this. |
| 987 | */ |
| 988 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 989 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 990 | /** |
| 991 | * Runtime permission state: The user can manage the permission |
| 992 | * through the UI. |
| 993 | */ |
| 994 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 995 | |
| 996 | /** |
| 997 | * Runtime permission state: The permission is granted to the app |
| 998 | * and the user cannot manage the permission through the UI. |
| 999 | */ |
| 1000 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1001 | |
| 1002 | /** |
| 1003 | * Runtime permission state: The permission is denied to the app |
| 1004 | * and the user cannot manage the permission through the UI. |
| 1005 | */ |
| 1006 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1007 | |
| 1008 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1009 | * No management for current user in-effect. This is the default. |
| 1010 | * @hide |
| 1011 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1012 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1013 | public static final int STATE_USER_UNMANAGED = 0; |
| 1014 | |
| 1015 | /** |
| 1016 | * Management partially setup, user setup needs to be completed. |
| 1017 | * @hide |
| 1018 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1019 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1020 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1021 | |
| 1022 | /** |
| 1023 | * Management partially setup, user setup completed. |
| 1024 | * @hide |
| 1025 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1026 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1027 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1028 | |
| 1029 | /** |
| 1030 | * Management setup and active on current user. |
| 1031 | * @hide |
| 1032 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1033 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1034 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1035 | |
| 1036 | /** |
| 1037 | * Management partially setup on a managed profile. |
| 1038 | * @hide |
| 1039 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1040 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1041 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1042 | |
| 1043 | /** |
| 1044 | * @hide |
| 1045 | */ |
| 1046 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1047 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1048 | @Retention(RetentionPolicy.SOURCE) |
| 1049 | public @interface UserProvisioningState {} |
| 1050 | |
| 1051 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1052 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1053 | * |
| 1054 | * @param admin The administrator component to check for. |
| 1055 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1056 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1057 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1058 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1059 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1060 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * @see #isAdminActive(ComponentName) |
| 1065 | * @hide |
| 1066 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1067 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1068 | if (mService != null) { |
| 1069 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1070 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1071 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1072 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | return false; |
| 1076 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1077 | /** |
| 1078 | * Return true if the given administrator component is currently being removed |
| 1079 | * for the user. |
| 1080 | * @hide |
| 1081 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1082 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1083 | if (mService != null) { |
| 1084 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1085 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1086 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1087 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | return false; |
| 1091 | } |
| 1092 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1093 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1094 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1095 | * Return a list of all currently active device administrators' component |
| 1096 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1097 | * returned. |
| 1098 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1099 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1100 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1101 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * @see #getActiveAdmins() |
| 1106 | * @hide |
| 1107 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1108 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1109 | if (mService != null) { |
| 1110 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1111 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1112 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1113 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | return null; |
| 1117 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1118 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1119 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1120 | * Used by package administration code to determine if a package can be stopped |
| 1121 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1122 | * @hide |
| 1123 | */ |
| 1124 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1125 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * Used by package administration code to determine if a package can be stopped |
| 1130 | * or uninstalled. |
| 1131 | * @hide |
| 1132 | */ |
| 1133 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1134 | if (mService != null) { |
| 1135 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1136 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1137 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1138 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | return false; |
| 1142 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1143 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1144 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1145 | * Remove a current administration component. This can only be called |
| 1146 | * by the application that owns the administration component; if you |
| 1147 | * try to remove someone else's component, a security exception will be |
| 1148 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1149 | * |
| 1150 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1151 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1152 | * |
| 1153 | * @param admin The administration compononent to remove. |
| 1154 | * @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] | 1155 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1156 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1157 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1158 | if (mService != null) { |
| 1159 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1160 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1161 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1162 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1166 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1167 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1168 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1169 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1170 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1171 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1172 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1173 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1174 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1175 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1176 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1177 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1178 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1179 | if (mService != null) { |
| 1180 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1181 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1182 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1183 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | return false; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1190 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1191 | * |
| 1192 | * @hide |
| 1193 | */ |
| 1194 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1195 | if (mService != null) { |
| 1196 | try { |
| 1197 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1198 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1199 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | return false; |
| 1203 | } |
| 1204 | |
| 1205 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1206 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1207 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1208 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1209 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1210 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1211 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1212 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1213 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1214 | * recognition technology. This implies technologies that can recognize the identity of |
| 1215 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1216 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1217 | */ |
| 1218 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1219 | |
| 1220 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1221 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1222 | * 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] | 1223 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1224 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1225 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1226 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1227 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1228 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1229 | * password containing at least numeric characters. Note that quality |
| 1230 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1231 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1232 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1233 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1234 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1235 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1236 | * password containing at least numeric characters with no repeating (4444) |
| 1237 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1238 | * constants are ordered so that higher values are more restrictive. |
| 1239 | */ |
| 1240 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1241 | |
| 1242 | /** |
| 1243 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1244 | * password containing at least alphabetic (or other symbol) characters. |
| 1245 | * Note that quality constants are ordered so that higher values are more |
| 1246 | * restrictive. |
| 1247 | */ |
| 1248 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1249 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1250 | /** |
| 1251 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1252 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1253 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1254 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1255 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1256 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1257 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1258 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1259 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1260 | * password containing at least a letter, a numerical digit and a special |
| 1261 | * symbol, by default. With this password quality, passwords can be |
| 1262 | * restricted to contain various sets of characters, like at least an |
| 1263 | * uppercase letter, etc. These are specified using various methods, |
| 1264 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1265 | * that quality constants are ordered so that higher values are more |
| 1266 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1267 | */ |
| 1268 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1269 | |
| 1270 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1271 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1272 | * modify password. In case this password quality is set, the password is |
| 1273 | * managed by a profile owner. The profile owner can set any password, |
| 1274 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1275 | * that quality constants are ordered so that higher values are more |
| 1276 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1277 | * the highest. |
| 1278 | * @hide |
| 1279 | */ |
| 1280 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1281 | |
| 1282 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1283 | * @hide |
| 1284 | * |
| 1285 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1286 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1287 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1288 | * used by authenticator to exempt their accounts from this: |
| 1289 | * |
| 1290 | * <ul> |
| 1291 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1292 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1293 | * <application> tag in the manifest. |
| 1294 | * |
| 1295 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1296 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1297 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1298 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1299 | * if any of the accounts have it. |
| 1300 | * </ul> |
| 1301 | */ |
| 1302 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1303 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1304 | |
| 1305 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
| 1306 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1307 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1308 | |
| 1309 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1310 | * Called by an application that is administering the device to set the password restrictions it |
| 1311 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1312 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1313 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1314 | * 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] | 1315 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1316 | * <p> |
| 1317 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1318 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1319 | * considerations) is the one that is in effect. |
| 1320 | * <p> |
| 1321 | * The calling device admin must have requested |
| 1322 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1323 | * not, a security exception will be thrown. |
| 1324 | * <p> |
| 1325 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1326 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1327 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1328 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1329 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1330 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1331 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1332 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1333 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1334 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1335 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1336 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1337 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1338 | if (mService != null) { |
| 1339 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1340 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1341 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1342 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1346 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1347 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1348 | * 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] | 1349 | * 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] | 1350 | * a separate challenge are not taken into account. |
| 1351 | * |
| 1352 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1353 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1354 | * restrictions on the parent profile. |
| 1355 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1356 | * @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] | 1357 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1358 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1359 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1360 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1364 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1365 | if (mService != null) { |
| 1366 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1367 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1368 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1369 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1370 | } |
| 1371 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1372 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1373 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1374 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1375 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1376 | * Called by an application that is administering the device to set the minimum allowed password |
| 1377 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1378 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1379 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1380 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1381 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1382 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1383 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1384 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1385 | * {@link #setPasswordQuality}. |
| 1386 | * <p> |
| 1387 | * The calling device admin must have requested |
| 1388 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1389 | * not, a security exception will be thrown. |
| 1390 | * <p> |
| 1391 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1392 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1393 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1394 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1395 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1396 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1397 | * restriction. |
| 1398 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1399 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1400 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1401 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1402 | if (mService != null) { |
| 1403 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1404 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1405 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1406 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1407 | } |
| 1408 | } |
| 1409 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1410 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1411 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1412 | * 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] | 1413 | * 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] | 1414 | * a separate challenge are not taken into account. |
| 1415 | * |
| 1416 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1417 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1418 | * restrictions on the parent profile. |
| 1419 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1420 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1421 | * @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] | 1422 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1423 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1424 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1425 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1429 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1430 | if (mService != null) { |
| 1431 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1432 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1433 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1434 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1435 | } |
| 1436 | } |
| 1437 | return 0; |
| 1438 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1439 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1440 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1441 | * Called by an application that is administering the device to set the minimum number of upper |
| 1442 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1443 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1444 | * current password will remain until the user has set a new one, so the change does not take |
| 1445 | * place immediately. To prompt the user for a new password, use |
| 1446 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1447 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1448 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1449 | * <p> |
| 1450 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1451 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1452 | * not, a security exception will be thrown. |
| 1453 | * <p> |
| 1454 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1455 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1456 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1457 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1458 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1459 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1460 | * A value of 0 means there is no restriction. |
| 1461 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1462 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1463 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1464 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1465 | if (mService != null) { |
| 1466 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1467 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1468 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1469 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1475 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1476 | * 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] | 1477 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1478 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1479 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1480 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1481 | * and only applies when the password quality is |
| 1482 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1483 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1484 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1485 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1486 | * restrictions on the parent profile. |
| 1487 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1488 | * @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] | 1489 | * aggregate all admins. |
| 1490 | * @return The minimum number of upper case letters required in the |
| 1491 | * password. |
| 1492 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1493 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1494 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1498 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1499 | if (mService != null) { |
| 1500 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1501 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1502 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1503 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
| 1509 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1510 | * Called by an application that is administering the device to set the minimum number of lower |
| 1511 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1512 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1513 | * current password will remain until the user has set a new one, so the change does not take |
| 1514 | * place immediately. To prompt the user for a new password, use |
| 1515 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1516 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1517 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1518 | * <p> |
| 1519 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1520 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1521 | * not, a security exception will be thrown. |
| 1522 | * <p> |
| 1523 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1524 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1525 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1526 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1527 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1528 | * @param length The new desired minimum number of lower case letters required in the password. |
| 1529 | * A value of 0 means there is no restriction. |
| 1530 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1531 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1532 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1533 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1534 | if (mService != null) { |
| 1535 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1536 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1537 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1538 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1544 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1545 | * 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] | 1546 | * and its participating profiles. Restrictions on profiles that have |
| 1547 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1548 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1549 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1550 | * and only applies when the password quality is |
| 1551 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1552 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1553 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1554 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1555 | * restrictions on the parent profile. |
| 1556 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1557 | * @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] | 1558 | * aggregate all admins. |
| 1559 | * @return The minimum number of lower case letters required in the |
| 1560 | * password. |
| 1561 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1562 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1563 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1567 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1568 | if (mService != null) { |
| 1569 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1570 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1571 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1572 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | return 0; |
| 1576 | } |
| 1577 | |
| 1578 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1579 | * Called by an application that is administering the device to set the minimum number of |
| 1580 | * letters required in the password. After setting this, the user will not be able to enter a |
| 1581 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1582 | * password will remain until the user has set a new one, so the change does not take place |
| 1583 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1584 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1585 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1586 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1587 | * <p> |
| 1588 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1589 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1590 | * not, a security exception will be thrown. |
| 1591 | * <p> |
| 1592 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1593 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1594 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1595 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1596 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1597 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1598 | * 0 means there is no restriction. |
| 1599 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1600 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1601 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1602 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1603 | if (mService != null) { |
| 1604 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1605 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1606 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1607 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1613 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1614 | * 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] | 1615 | * and its participating profiles. Restrictions on profiles that have |
| 1616 | * a separate challenge are not taken into account. |
| 1617 | * This is the same value as set by |
| 1618 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1619 | * and only applies when the password quality is |
| 1620 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1621 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1622 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1623 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1624 | * restrictions on the parent profile. |
| 1625 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1626 | * @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] | 1627 | * aggregate all admins. |
| 1628 | * @return The minimum number of letters required in the password. |
| 1629 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1630 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1631 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1635 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1636 | if (mService != null) { |
| 1637 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1638 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1639 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1640 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1647 | * Called by an application that is administering the device to set the minimum number of |
| 1648 | * numerical digits required in the password. After setting this, the user will not be able to |
| 1649 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 1650 | * current password will remain until the user has set a new one, so the change does not take |
| 1651 | * place immediately. To prompt the user for a new password, use |
| 1652 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1653 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1654 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1655 | * <p> |
| 1656 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1657 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1658 | * not, a security exception will be thrown. |
| 1659 | * <p> |
| 1660 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1661 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1662 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1663 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1664 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1665 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 1666 | * value of 0 means there is no restriction. |
| 1667 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1668 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1669 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1670 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1671 | if (mService != null) { |
| 1672 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1673 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1674 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1675 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | /** |
| 1681 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1682 | * 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] | 1683 | * and its participating profiles. Restrictions on profiles that have |
| 1684 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1685 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1686 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1687 | * and only applies when the password quality is |
| 1688 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1689 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1690 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1691 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1692 | * restrictions on the parent profile. |
| 1693 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1694 | * @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] | 1695 | * aggregate all admins. |
| 1696 | * @return The minimum number of numerical digits required in the password. |
| 1697 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1698 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1699 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1703 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1704 | if (mService != null) { |
| 1705 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1706 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1707 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1708 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | return 0; |
| 1712 | } |
| 1713 | |
| 1714 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1715 | * Called by an application that is administering the device to set the minimum number of |
| 1716 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 1717 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1718 | * password will remain until the user has set a new one, so the change does not take place |
| 1719 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1720 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1721 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1722 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1723 | * <p> |
| 1724 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1725 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1726 | * not, a security exception will be thrown. |
| 1727 | * <p> |
| 1728 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1729 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1730 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1731 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1732 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1733 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 1734 | * 0 means there is no restriction. |
| 1735 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1736 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1737 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1738 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1739 | if (mService != null) { |
| 1740 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1741 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1742 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1743 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1749 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1750 | * 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] | 1751 | * and its participating profiles. Restrictions on profiles that have |
| 1752 | * a separate challenge are not taken into account. This is the same value as |
| 1753 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1754 | * and only applies when the password quality is |
| 1755 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1756 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1757 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1758 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1759 | * restrictions on the parent profile. |
| 1760 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1761 | * @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] | 1762 | * aggregate all admins. |
| 1763 | * @return The minimum number of symbols required in the password. |
| 1764 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1765 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1766 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1770 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1771 | if (mService != null) { |
| 1772 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1773 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1774 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1775 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | return 0; |
| 1779 | } |
| 1780 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1781 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1782 | * Called by an application that is administering the device to set the minimum number of |
| 1783 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 1784 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 1785 | * as what has been set. Note that the current password will remain until the user has set a new |
| 1786 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 1787 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1788 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1789 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1790 | * <p> |
| 1791 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1792 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1793 | * not, a security exception will be thrown. |
| 1794 | * <p> |
| 1795 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1796 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1797 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1798 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1799 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1800 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1801 | * 0 means there is no restriction. |
| 1802 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1803 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1804 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1805 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1806 | if (mService != null) { |
| 1807 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1808 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1809 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1810 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1816 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1817 | * 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] | 1818 | * and its participating profiles. Restrictions on profiles that have |
| 1819 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1820 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1821 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1822 | * and only applies when the password quality is |
| 1823 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1824 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1825 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1826 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1827 | * restrictions on the parent profile. |
| 1828 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1829 | * @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] | 1830 | * aggregate all admins. |
| 1831 | * @return The minimum number of letters required in the password. |
| 1832 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1833 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1834 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1838 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1839 | if (mService != null) { |
| 1840 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1841 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1842 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1843 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1849 | /** |
| 1850 | * Called by an application that is administering the device to set the length of the password |
| 1851 | * history. After setting this, the user will not be able to enter a new password that is the |
| 1852 | * same as any password in the history. Note that the current password will remain until the |
| 1853 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 1854 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1855 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1856 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1857 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 1858 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 1859 | * <p> |
| 1860 | * The calling device admin must have requested |
| 1861 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1862 | * not, a security exception will be thrown. |
| 1863 | * <p> |
| 1864 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1865 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1866 | * profile. |
| 1867 | * |
| 1868 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1869 | * @param length The new desired length of password history. A value of 0 means there is no |
| 1870 | * restriction. |
| 1871 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1872 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 1873 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1874 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1875 | if (mService != null) { |
| 1876 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1877 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1878 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1879 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1885 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 1886 | * restart the countdown for password expiration for the given admin, as will changing the |
| 1887 | * device password (for all admins). |
| 1888 | * <p> |
| 1889 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 1890 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 1891 | * 432000000 ms for timeout. |
| 1892 | * <p> |
| 1893 | * To disable password expiration, a value of 0 may be used for timeout. |
| 1894 | * <p> |
| 1895 | * The calling device admin must have requested |
| 1896 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 1897 | * not, a security exception will be thrown. |
| 1898 | * <p> |
| 1899 | * Note that setting the password will automatically reset the expiration time for all active |
| 1900 | * admins. Active admins do not need to explicitly call this method in that case. |
| 1901 | * <p> |
| 1902 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1903 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1904 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1905 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1906 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1907 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 1908 | * there is no restriction (unlimited). |
| 1909 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1910 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1911 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1912 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1913 | if (mService != null) { |
| 1914 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1915 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1916 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1917 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1923 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1924 | * recurring expiration timeout provided in the call to |
| 1925 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1926 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 1927 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 1928 | * |
| 1929 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1930 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1931 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1932 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1933 | * @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] | 1934 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1935 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1936 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1937 | if (mService != null) { |
| 1938 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1939 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1940 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1941 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | return 0; |
| 1945 | } |
| 1946 | |
| 1947 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1948 | * 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] | 1949 | * 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] | 1950 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 1951 | * of all expiration times is returned - which will be the minimum of all of them. |
| 1952 | * |
| 1953 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1954 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1955 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1956 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1957 | * @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] | 1958 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1959 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1960 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1961 | if (mService != null) { |
| 1962 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1963 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1964 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1965 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1972 | * 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] | 1973 | * 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] | 1974 | * have a separate challenge are not taken into account. |
| 1975 | * |
| 1976 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1977 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1978 | * restrictions on the parent profile. |
| 1979 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1980 | * @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] | 1981 | * all admins. |
| 1982 | * @return The length of the password history |
| 1983 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1984 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1985 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1989 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1990 | if (mService != null) { |
| 1991 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1992 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1993 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1994 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1995 | } |
| 1996 | } |
| 1997 | return 0; |
| 1998 | } |
| 1999 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2000 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2001 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2002 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2003 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2004 | * @return Returns the maximum length that the user can enter. |
| 2005 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2006 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2007 | // Kind-of arbitrary. |
| 2008 | return 16; |
| 2009 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2010 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2011 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2012 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2013 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2014 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
| 2015 | * are not taken into account. |
| 2016 | * <p> |
| 2017 | * The calling device admin must have requested |
| 2018 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2019 | * not, a security exception will be thrown. |
| 2020 | * <p> |
| 2021 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2022 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2023 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2024 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2025 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2026 | * @throws SecurityException if the calling application does not own an active administrator |
| 2027 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2028 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2029 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2030 | if (mService != null) { |
| 2031 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2032 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2033 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2034 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2035 | } |
| 2036 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2037 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2038 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2039 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2040 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2041 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2042 | * 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] | 2043 | * requested by the admins of the parent user and its profiles. |
| 2044 | * |
| 2045 | * @param userHandle the userId of the profile to check the password for. |
| 2046 | * @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] | 2047 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2048 | * @hide |
| 2049 | */ |
| 2050 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2051 | if (mService != null) { |
| 2052 | try { |
| 2053 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2054 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2055 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2056 | } |
| 2057 | } |
| 2058 | return false; |
| 2059 | } |
| 2060 | |
| 2061 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2062 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2063 | * successful password entry. |
| 2064 | * <p> |
| 2065 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2066 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2067 | * password attemts for the parent user. |
| 2068 | * <p> |
| 2069 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2070 | * 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] | 2071 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2072 | * @return The number of times user has entered an incorrect password since the last correct |
| 2073 | * password entry. |
| 2074 | * @throws SecurityException if the calling application does not own an active administrator |
| 2075 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2076 | */ |
| 2077 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2078 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2079 | } |
| 2080 | |
| 2081 | /** |
| 2082 | * Retrieve the number of times the given user has failed at entering a |
| 2083 | * password since that last successful password entry. |
| 2084 | * |
| 2085 | * <p>The calling device admin must have requested |
| 2086 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2087 | * not and it is not the system uid, a security exception will be thrown. |
| 2088 | * |
| 2089 | * @hide |
| 2090 | */ |
| 2091 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2092 | if (mService != null) { |
| 2093 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2094 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2095 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2096 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | return -1; |
| 2100 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2101 | |
| 2102 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2103 | * 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] | 2104 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2105 | * @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] | 2106 | * @hide |
| 2107 | */ |
| 2108 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2109 | if (mService != null) { |
| 2110 | try { |
| 2111 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2112 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2113 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | return false; |
| 2117 | } |
| 2118 | |
| 2119 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2120 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2121 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2122 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2123 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2124 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2125 | * <p> |
| 2126 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2127 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2128 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2129 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2130 | * immediately, and your callback will not be invoked. |
| 2131 | * <p> |
| 2132 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2133 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2134 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2135 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2136 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2137 | * @param num The number of failed password attempts at which point the device or profile will |
| 2138 | * be wiped. |
| 2139 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2140 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2141 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2142 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2143 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2144 | if (mService != null) { |
| 2145 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2146 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2147 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2148 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2149 | } |
| 2150 | } |
| 2151 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2152 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2153 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2154 | * 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] | 2155 | * 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] | 2156 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2157 | * not taken into account. |
| 2158 | * |
| 2159 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2160 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2161 | * the value for the parent profile. |
| 2162 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2163 | * @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] | 2164 | * all admins. |
| 2165 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2166 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2167 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2171 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2172 | if (mService != null) { |
| 2173 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2174 | return mService.getMaximumFailedPasswordsForWipe( |
| 2175 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2176 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2177 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | return 0; |
| 2181 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2182 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2183 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2184 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2185 | * for the given user. So for primary user, it might return the primary or |
| 2186 | * a managed profile. For a secondary user, it would be the same as the |
| 2187 | * user passed in. |
| 2188 | * @hide Used only by Keyguard |
| 2189 | */ |
| 2190 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2191 | if (mService != null) { |
| 2192 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2193 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2194 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2195 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2196 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2197 | } |
| 2198 | } |
| 2199 | return UserHandle.USER_NULL; |
| 2200 | } |
| 2201 | |
| 2202 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2203 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2204 | * the password again until the user has entered it. |
| 2205 | */ |
| 2206 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2207 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2208 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2209 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2210 | * If the flag is set, the device can be booted without asking for user password. |
| 2211 | * The absence of this flag does not change the current boot requirements. This flag |
| 2212 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2213 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2214 | * device to factory defaults. |
| 2215 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2216 | 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] | 2217 | |
| 2218 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2219 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2220 | * individual accounts) on the user. This takes effect immediately. |
| 2221 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2222 | * <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] | 2223 | * device admins that are not device owner and not profile owner. |
| 2224 | * 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] | 2225 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2226 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2227 | * <p> |
| 2228 | * The given password must be sufficient for the current password quality and length constraints |
| 2229 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2230 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2231 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2232 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2233 | * case the currently active quality will be increased to match. |
| 2234 | * <p> |
| 2235 | * 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] | 2236 | * current password constraints allow it. <em>Note: This will not work in |
| 2237 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2238 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2239 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2240 | * <p> |
| 2241 | * The calling device admin must have requested |
| 2242 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2243 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2244 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2245 | * @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] | 2246 | * @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] | 2247 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2248 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2249 | * current constraints or if the user has not been decrypted yet. |
| 2250 | * @throws SecurityException if the calling application does not own an active administrator |
| 2251 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2252 | * @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] | 2253 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2254 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2255 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2256 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2257 | if (mService != null) { |
| 2258 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2259 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2260 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2261 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | return false; |
| 2265 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2266 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2267 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2268 | * Called by an application that is administering the device to set the maximum time for user |
| 2269 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2270 | * effect immediately. |
| 2271 | * <p> |
| 2272 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2273 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2274 | * <p> |
| 2275 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2276 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2277 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2278 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2279 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2280 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2281 | * is no restriction. |
| 2282 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2283 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2284 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2285 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2286 | if (mService != null) { |
| 2287 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2288 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2289 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2290 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2291 | } |
| 2292 | } |
| 2293 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2294 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2295 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2296 | * 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] | 2297 | * 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] | 2298 | * a separate challenge are not taken into account. |
| 2299 | * |
| 2300 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2301 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2302 | * restrictions on the parent profile. |
| 2303 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2304 | * @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] | 2305 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2306 | * @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] | 2307 | * 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] | 2308 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2309 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2310 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2314 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2315 | if (mService != null) { |
| 2316 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2317 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2318 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2319 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | return 0; |
| 2323 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2324 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2325 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2326 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2327 | * do not have a separate timeout to lock for work challenge only. |
| 2328 | * |
| 2329 | * @hide |
| 2330 | */ |
| 2331 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2332 | if (mService != null) { |
| 2333 | try { |
| 2334 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2335 | } catch (RemoteException e) { |
| 2336 | throw e.rethrowFromSystemServer(); |
| 2337 | } |
| 2338 | } |
| 2339 | return 0; |
| 2340 | } |
| 2341 | |
| 2342 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2343 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2344 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2345 | * authentication method like password, pin or pattern. |
| 2346 | * |
| 2347 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2348 | * specified timeout each time it has been successfully used. |
| 2349 | * |
| 2350 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2351 | * |
| 2352 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2353 | * |
| 2354 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2355 | * a {@link SecurityException} will be thrown. |
| 2356 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2357 | * <p>The calling device admin can verify the value it has set by calling |
| 2358 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2359 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2360 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2361 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2362 | * profile. |
| 2363 | * |
| 2364 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2365 | * @param timeoutMs The new timeout, after which the user will have to unlock with strong |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2366 | * authentication method. A value of 0 means the admin is not participating in |
| 2367 | * controlling the timeout. |
| 2368 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2369 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2370 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2371 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2372 | * |
| 2373 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2374 | * |
| 2375 | * @hide |
| 2376 | */ |
| 2377 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2378 | long timeoutMs) { |
| 2379 | if (mService != null) { |
| 2380 | try { |
| 2381 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2382 | } catch (RemoteException e) { |
| 2383 | throw e.rethrowFromSystemServer(); |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | /** |
| 2389 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 2390 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 2391 | * After the returned timeout the user is required to use strong authentication method. |
| 2392 | * |
| 2393 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2394 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2395 | * restrictions on the parent profile. |
| 2396 | * |
| 2397 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 2398 | * accross all participating admins. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2399 | * @return The timeout or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2400 | * |
| 2401 | * @hide |
| 2402 | */ |
| 2403 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 2404 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 2405 | } |
| 2406 | |
| 2407 | /** @hide per-user version */ |
| 2408 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 2409 | if (mService != null) { |
| 2410 | try { |
| 2411 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 2412 | } catch (RemoteException e) { |
| 2413 | throw e.rethrowFromSystemServer(); |
| 2414 | } |
| 2415 | } |
| 2416 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 2417 | } |
| 2418 | |
| 2419 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2420 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2421 | * this call. |
| 2422 | * <p> |
| 2423 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2424 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2425 | * <p> |
| 2426 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2427 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2428 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2429 | * @throws SecurityException if the calling application does not own an active administrator |
| 2430 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2431 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2432 | public void lockNow() { |
| 2433 | if (mService != null) { |
| 2434 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2435 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2436 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2437 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2441 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2442 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2443 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2444 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2445 | */ |
| 2446 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2447 | |
| 2448 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2449 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2450 | * data. |
| 2451 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2452 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2453 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2454 | */ |
| 2455 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2456 | |
| 2457 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 2458 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 2459 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 2460 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 2461 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2462 | * <p> |
| 2463 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2464 | * 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] | 2465 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2466 | * @param flags Bit mask of additional options: currently supported flags are |
| 2467 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2468 | * @throws SecurityException if the calling application does not own an active administrator |
| 2469 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2470 | */ |
| 2471 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2472 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2473 | if (mService != null) { |
| 2474 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2475 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2476 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2477 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2481 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2482 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2483 | * Called by an application that is administering the device to set the |
| 2484 | * global proxy and exclusion list. |
| 2485 | * <p> |
| 2486 | * The calling device admin must have requested |
| 2487 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2488 | * this method; if it has not, a security exception will be thrown. |
| 2489 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2490 | * 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] | 2491 | * 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] | 2492 | * be returned. |
| 2493 | * The method can be called repeatedly by the device admin alrady setting the |
| 2494 | * proxy to update the proxy and exclusion list. |
| 2495 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2496 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2497 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2498 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2499 | * @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] | 2500 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2501 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2502 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2503 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2504 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2505 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2506 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2507 | if (proxySpec == null) { |
| 2508 | throw new NullPointerException(); |
| 2509 | } |
| 2510 | if (mService != null) { |
| 2511 | try { |
| 2512 | String hostSpec; |
| 2513 | String exclSpec; |
| 2514 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2515 | hostSpec = null; |
| 2516 | exclSpec = null; |
| 2517 | } else { |
| 2518 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2519 | throw new IllegalArgumentException(); |
| 2520 | } |
| 2521 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2522 | String hostName = sa.getHostName(); |
| 2523 | int port = sa.getPort(); |
| 2524 | StringBuilder hostBuilder = new StringBuilder(); |
| 2525 | hostSpec = hostBuilder.append(hostName) |
| 2526 | .append(":").append(Integer.toString(port)).toString(); |
| 2527 | if (exclusionList == null) { |
| 2528 | exclSpec = ""; |
| 2529 | } else { |
| 2530 | StringBuilder listBuilder = new StringBuilder(); |
| 2531 | boolean firstDomain = true; |
| 2532 | for (String exclDomain : exclusionList) { |
| 2533 | if (!firstDomain) { |
| 2534 | listBuilder = listBuilder.append(","); |
| 2535 | } else { |
| 2536 | firstDomain = false; |
| 2537 | } |
| 2538 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2539 | } |
| 2540 | exclSpec = listBuilder.toString(); |
| 2541 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2542 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2543 | != android.net.Proxy.PROXY_VALID) |
| 2544 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2545 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2546 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2547 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2548 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2549 | } |
| 2550 | } |
| 2551 | return null; |
| 2552 | } |
| 2553 | |
| 2554 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2555 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 2556 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 2557 | * unusual like general internal filtering this may be useful. On a private network where the |
| 2558 | * proxy is not accessible, you may break HTTP using this. |
| 2559 | * <p> |
| 2560 | * This method requires the caller to be the device owner. |
| 2561 | * <p> |
| 2562 | * 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] | 2563 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2564 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2565 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2566 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 2567 | * {@code null} value will clear the global HTTP proxy. |
| 2568 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2569 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2570 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2571 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2572 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2573 | if (mService != null) { |
| 2574 | try { |
| 2575 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2576 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2577 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2583 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2584 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2585 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2586 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2587 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2588 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2589 | if (mService != null) { |
| 2590 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2591 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2592 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2593 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2594 | } |
| 2595 | } |
| 2596 | return null; |
| 2597 | } |
| 2598 | |
| 2599 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2600 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2601 | * indicating that encryption is not supported. |
| 2602 | */ |
| 2603 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2604 | |
| 2605 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2606 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2607 | * indicating that encryption is supported, but is not currently active. |
| 2608 | */ |
| 2609 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2610 | |
| 2611 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2612 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2613 | * indicating that encryption is not currently active, but is currently |
| 2614 | * being activated. This is only reported by devices that support |
| 2615 | * encryption of data and only when the storage is currently |
| 2616 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2617 | * to become encrypted will never return this value. |
| 2618 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2619 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2620 | |
| 2621 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2622 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2623 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2624 | * <p> |
| 2625 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2626 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2627 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2628 | |
| 2629 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2630 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2631 | * indicating that encryption is active, but an encryption key has not |
| 2632 | * been set by the user. |
| 2633 | */ |
| 2634 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2635 | |
| 2636 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2637 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2638 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 2639 | * <p> |
| 2640 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 2641 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 2642 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2643 | */ |
| 2644 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 2645 | |
| 2646 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2647 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2648 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2649 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2650 | * to check encryption status. However, on some devices this activity may never return, as |
| 2651 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2652 | */ |
| 2653 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2654 | public static final String ACTION_START_ENCRYPTION |
| 2655 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2656 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2657 | * Widgets are enabled in keyguard |
| 2658 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2659 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2660 | |
| 2661 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2662 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2663 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2664 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2665 | |
| 2666 | /** |
| 2667 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2668 | */ |
| 2669 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2670 | |
| 2671 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2672 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2673 | */ |
| 2674 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2675 | |
| 2676 | /** |
| 2677 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2678 | */ |
| 2679 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2680 | |
| 2681 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2682 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2683 | * (e.g. PIN/Pattern/Password). |
| 2684 | */ |
| 2685 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2686 | |
| 2687 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2688 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2689 | */ |
| 2690 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2691 | |
| 2692 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 2693 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 2694 | */ |
| 2695 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 2696 | |
| 2697 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2698 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2699 | */ |
| 2700 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2701 | |
| 2702 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2703 | * Called by an application that is administering the device to request that the storage system |
| 2704 | * be encrypted. |
| 2705 | * <p> |
| 2706 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 2707 | * supported setting will always be used. If any device administrator requests device |
| 2708 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 2709 | * 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] | 2710 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2711 | * <p> |
| 2712 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 2713 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 2714 | * control the encryption of any other storage areas. There is one exception: If |
| 2715 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 2716 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 2717 | * written to disk within the encrypted storage area. |
| 2718 | * <p> |
| 2719 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 2720 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 2721 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 2722 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2723 | * |
| 2724 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2725 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2726 | * @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] | 2727 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2728 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2729 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 2730 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2731 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2732 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2733 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2734 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2735 | if (mService != null) { |
| 2736 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2737 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2738 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2739 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2740 | } |
| 2741 | } |
| 2742 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2743 | } |
| 2744 | |
| 2745 | /** |
| 2746 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2747 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2748 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2749 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2750 | * this will return the requested encryption setting as an aggregate of all active |
| 2751 | * administrators. |
| 2752 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2753 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2754 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2755 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2756 | if (mService != null) { |
| 2757 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2758 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2759 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2760 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2761 | } |
| 2762 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2763 | return false; |
| 2764 | } |
| 2765 | |
| 2766 | /** |
| 2767 | * Called by an application that is administering the device to |
| 2768 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2769 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2770 | * Depending on the returned status code, the caller may proceed in different |
| 2771 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2772 | * storage system does not support encryption. If the |
| 2773 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2774 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2775 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2776 | * 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] | 2777 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 2778 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 2779 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2780 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2781 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2782 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2783 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2784 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2785 | */ |
| 2786 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2787 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2788 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | /** @hide per-user version */ |
| 2792 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2793 | if (mService != null) { |
| 2794 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2795 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2796 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2797 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2798 | } |
| 2799 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2800 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2801 | } |
| 2802 | |
| 2803 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 2804 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 2805 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 2806 | * keep the certificate on the device. |
| 2807 | * |
| 2808 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 2809 | * this certificate. |
| 2810 | * |
| 2811 | * @hide |
| 2812 | */ |
| 2813 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 2814 | if (mService != null) { |
| 2815 | try { |
| 2816 | return mService.approveCaCert(alias, userHandle, approval); |
| 2817 | } catch (RemoteException e) { |
| 2818 | throw e.rethrowFromSystemServer(); |
| 2819 | } |
| 2820 | } |
| 2821 | return false; |
| 2822 | } |
| 2823 | |
| 2824 | /** |
| 2825 | * Check whether a CA certificate has been approved by the device user. |
| 2826 | * |
| 2827 | * @hide |
| 2828 | */ |
| 2829 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 2830 | if (mService != null) { |
| 2831 | try { |
| 2832 | return mService.isCaCertApproved(alias, userHandle); |
| 2833 | } catch (RemoteException e) { |
| 2834 | throw e.rethrowFromSystemServer(); |
| 2835 | } |
| 2836 | } |
| 2837 | return false; |
| 2838 | } |
| 2839 | |
| 2840 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2841 | * Installs the given certificate as a user CA. |
| 2842 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2843 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2844 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2845 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2846 | * |
| 2847 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2848 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2849 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2850 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2851 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2852 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2853 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2854 | if (mService != null) { |
| 2855 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2856 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2857 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2858 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2859 | } |
| 2860 | } |
| 2861 | return false; |
| 2862 | } |
| 2863 | |
| 2864 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2865 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2866 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2867 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2868 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2869 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2870 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2871 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2872 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2873 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2874 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2875 | if (mService != null) { |
| 2876 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2877 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2878 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2879 | } catch (CertificateException e) { |
| 2880 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2881 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2882 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2883 | } |
| 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2888 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2889 | * If a user has installed any certificates by other means than device policy these will be |
| 2890 | * included too. |
| 2891 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2892 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2893 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2894 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2895 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2896 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2897 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2898 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 2899 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2900 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2901 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2902 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2903 | mService.enforceCanManageCaCerts(admin); |
| 2904 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2905 | for (String alias : certStore.userAliases()) { |
| 2906 | try { |
| 2907 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2908 | } catch (CertificateException ce) { |
| 2909 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2910 | } |
| 2911 | } |
| 2912 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2913 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2914 | } |
| 2915 | } |
| 2916 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2920 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2921 | * means other than device policy will also be removed, except for system CA certificates. |
| 2922 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2923 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2924 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2925 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2926 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2927 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2928 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2929 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2930 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2931 | try { |
| 2932 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2933 | .toArray(new String[0])); |
| 2934 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2935 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2936 | } |
| 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | /** |
| 2941 | * Returns whether this certificate is installed as a trusted CA. |
| 2942 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2943 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2944 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2945 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2946 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2947 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2948 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2949 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2950 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2951 | if (mService != null) { |
| 2952 | try { |
| 2953 | mService.enforceCanManageCaCerts(admin); |
| 2954 | return getCaCertAlias(certBuffer) != null; |
| 2955 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2956 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2957 | } catch (CertificateException ce) { |
| 2958 | Log.w(TAG, "Could not parse certificate", ce); |
| 2959 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2960 | } |
| 2961 | return false; |
| 2962 | } |
| 2963 | |
| 2964 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2965 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2966 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2967 | * the certificate and use the private key, given direct user approval. |
| 2968 | * |
| 2969 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 2970 | * direct user approval. This is for security - should a certificate installer become |
| 2971 | * compromised, certificates it had already installed will be protected. |
| 2972 | * |
| 2973 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2974 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2975 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2976 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2977 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2978 | * @param privKey The private key to install. |
| 2979 | * @param cert The certificate to install. |
| 2980 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2981 | * with that alias already exists, it will be overwritten. |
| 2982 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2983 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2984 | * owner. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2985 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2986 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2987 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2988 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | /** |
| 2992 | * 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] | 2993 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 2994 | * profile will be able to access the certificate chain and use the private key, given direct |
| 2995 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2996 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2997 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 2998 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 2999 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3000 | * |
| 3001 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3002 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3003 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3004 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3005 | * certificate and include the chain of trust in order. This will be returned by |
| 3006 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3007 | * @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] | 3008 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3009 | * @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] | 3010 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3011 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3012 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3013 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3014 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3015 | * @see android.security.KeyChain#getCertificateChain |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3016 | */ |
| 3017 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3018 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3019 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3020 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3021 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3022 | byte[] pemChain = null; |
| 3023 | if (certs.length > 1) { |
| 3024 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3025 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3026 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3027 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3028 | return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias, |
| 3029 | requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3030 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3031 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3032 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3033 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3034 | } catch (CertificateException | IOException e) { |
| 3035 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3036 | } |
| 3037 | return false; |
| 3038 | } |
| 3039 | |
| 3040 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3041 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3042 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3043 | * |
| 3044 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3045 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3046 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3047 | * @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] | 3048 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3049 | * owner. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3050 | */ |
| 3051 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3052 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3053 | try { |
| 3054 | return mService.removeKeyPair(admin, alias); |
| 3055 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3056 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3057 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3061 | * @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] | 3062 | * doesn't exist. |
| 3063 | */ |
| 3064 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3065 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3066 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3067 | new ByteArrayInputStream(certBuffer)); |
| 3068 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3069 | } |
| 3070 | |
| 3071 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3072 | * 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] | 3073 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3074 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3075 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3076 | * <p> |
| 3077 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3078 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3079 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3080 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3081 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3082 | * 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] | 3083 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3084 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3085 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3086 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3087 | * @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] | 3088 | * access. If {@code null} is given the current package will be cleared. |
| 3089 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3090 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3091 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3092 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3093 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3094 | if (mService != null) { |
| 3095 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3096 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3097 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3098 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3104 | * Called by a profile owner or device owner to retrieve the certificate installer for the user. |
| 3105 | * null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3106 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3107 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3108 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3109 | * none is set. |
| 3110 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3111 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3112 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3113 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3114 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3115 | if (mService != null) { |
| 3116 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3117 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3118 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3119 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3120 | } |
| 3121 | } |
| 3122 | return null; |
| 3123 | } |
| 3124 | |
| 3125 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3126 | * 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] | 3127 | * specific application for the current user. |
| 3128 | * |
| 3129 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3130 | * TODO: delete once there are no longer any live references. |
| 3131 | * @hide |
| 3132 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3133 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3134 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3135 | throws NameNotFoundException, UnsupportedOperationException { |
| 3136 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3137 | } |
| 3138 | |
| 3139 | /** |
| 3140 | * 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] | 3141 | * specific application for the current user. This connection is automatically granted and |
| 3142 | * persisted after a reboot. |
| 3143 | * <p> |
| 3144 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3145 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3146 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3147 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3148 | * @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] | 3149 | * remove an existing always-on VPN configuration. |
| 3150 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3151 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3152 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3153 | * @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] | 3154 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3155 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3156 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3157 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3158 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3159 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3160 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3161 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3162 | if (mService != null) { |
| 3163 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3164 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3165 | throw new NameNotFoundException(vpnPackage); |
| 3166 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3167 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3168 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3169 | } |
| 3170 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | /** |
| 3174 | * 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] | 3175 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3176 | * 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] | 3177 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3178 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3179 | * is set. |
| 3180 | * @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] | 3181 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3182 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3183 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3184 | if (mService != null) { |
| 3185 | try { |
| 3186 | return mService.getAlwaysOnVpnPackage(admin); |
| 3187 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3188 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | return null; |
| 3192 | } |
| 3193 | |
| 3194 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3195 | * Called by an application that is administering the device to disable all cameras on the |
| 3196 | * device, for this user. After setting this, no applications running as this user will be able |
| 3197 | * to access any cameras on the device. |
| 3198 | * <p> |
| 3199 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3200 | * <p> |
| 3201 | * The calling device admin must have requested |
| 3202 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3203 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3204 | * |
| 3205 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3206 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3207 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3208 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3209 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3210 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3211 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3212 | if (mService != null) { |
| 3213 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3214 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3215 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3216 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3222 | * 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] | 3223 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3224 | * @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] | 3225 | * have disabled the camera |
| 3226 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3227 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3228 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3229 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3233 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3234 | if (mService != null) { |
| 3235 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3236 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3237 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3238 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3239 | } |
| 3240 | } |
| 3241 | return false; |
| 3242 | } |
| 3243 | |
| 3244 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3245 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3246 | * <p> |
| 3247 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 3248 | * {@link SecurityException} will be thrown. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3249 | * |
| 3250 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3251 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3252 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3253 | * bugreport is still running or waiting for the user to share or decline) |
| 3254 | * @throws SecurityException if {@code admin} is not a device owner, or if there are users other |
| 3255 | * than the one managed by the device owner. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3256 | */ |
| 3257 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3258 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3259 | if (mService != null) { |
| 3260 | try { |
| 3261 | return mService.requestBugreport(admin); |
| 3262 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3263 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3264 | } |
| 3265 | } |
| 3266 | return false; |
| 3267 | } |
| 3268 | |
| 3269 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3270 | * Determine whether or not creating a guest user has been disabled for the device |
| 3271 | * |
| 3272 | * @hide |
| 3273 | */ |
| 3274 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3275 | // Currently guest users can always be created if multi-user is enabled |
| 3276 | // TODO introduce a policy for guest user creation |
| 3277 | return false; |
| 3278 | } |
| 3279 | |
| 3280 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3281 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3282 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3283 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3284 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3285 | * <p> |
| 3286 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3287 | * exception will be thrown. |
| 3288 | * <p> |
| 3289 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3290 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3291 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3292 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3293 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3294 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3295 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3296 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3297 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3298 | if (mService != null) { |
| 3299 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3300 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3301 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3302 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3303 | } |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3308 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3309 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3310 | * @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] | 3311 | * have disabled screen capture. |
| 3312 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3313 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3314 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3315 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3319 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3320 | if (mService != null) { |
| 3321 | try { |
| 3322 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3323 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3324 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3325 | } |
| 3326 | } |
| 3327 | return false; |
| 3328 | } |
| 3329 | |
| 3330 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3331 | * Called by a device owner to set whether auto time is required. If auto time is required the |
| 3332 | * user cannot set the date and time, but has to use network date and time. |
| 3333 | * <p> |
| 3334 | * Note: if auto time is required the user can still manually set the time zone. |
| 3335 | * <p> |
| 3336 | * The calling device admin must be a device owner. If it is not, a security exception will be |
| 3337 | * thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3338 | * |
| 3339 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3340 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3341 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3342 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3343 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3344 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3345 | if (mService != null) { |
| 3346 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3347 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3348 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3349 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3350 | } |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | /** |
| 3355 | * @return true if auto time is required. |
| 3356 | */ |
| 3357 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3358 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3359 | if (mService != null) { |
| 3360 | try { |
| 3361 | return mService.getAutoTimeRequired(); |
| 3362 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3363 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3364 | } |
| 3365 | } |
| 3366 | return false; |
| 3367 | } |
| 3368 | |
| 3369 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3370 | * 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] | 3371 | * <p> |
| 3372 | * The system user is exempt from this policy - it is never ephemeral. |
| 3373 | * <p> |
| 3374 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 3375 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3376 | * |
| 3377 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3378 | * @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] | 3379 | * subsequently created users will be ephemeral. |
| 3380 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3381 | * @hide |
| 3382 | */ |
| 3383 | public void setForceEphemeralUsers( |
| 3384 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3385 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3386 | if (mService != null) { |
| 3387 | try { |
| 3388 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3389 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3390 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3391 | } |
| 3392 | } |
| 3393 | } |
| 3394 | |
| 3395 | /** |
| 3396 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3397 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3398 | * @hide |
| 3399 | */ |
| 3400 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3401 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3402 | if (mService != null) { |
| 3403 | try { |
| 3404 | return mService.getForceEphemeralUsers(admin); |
| 3405 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3406 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | return false; |
| 3410 | } |
| 3411 | |
| 3412 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3413 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3414 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3415 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3416 | * <p> |
| 3417 | * The calling device admin must have requested |
| 3418 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 3419 | * if it has not, a security exception will be thrown. |
| 3420 | * <p> |
| 3421 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 3422 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 3423 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3424 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3425 | * <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] | 3426 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3427 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3428 | * there is one, or the parent user otherwise. |
| 3429 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 3430 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3431 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3432 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3433 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3434 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3435 | * profile. |
| 3436 | * <p> |
| 3437 | * Requests to disable other features on a managed profile will be ignored. |
| 3438 | * <p> |
| 3439 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3440 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3441 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3442 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3443 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3444 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 3445 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 3446 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 3447 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 3448 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 3449 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 3450 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3451 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3452 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3453 | if (mService != null) { |
| 3454 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3455 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3456 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3457 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | } |
| 3461 | |
| 3462 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3463 | * 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] | 3464 | * 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] | 3465 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3466 | * |
| 3467 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3468 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3469 | * restrictions on the parent profile. |
| 3470 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3471 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3472 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3473 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3474 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3475 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3476 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3477 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3481 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3482 | if (mService != null) { |
| 3483 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3484 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3485 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3486 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3487 | } |
| 3488 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3489 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3493 | * @hide |
| 3494 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3495 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3496 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3497 | if (mService != null) { |
| 3498 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3499 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3500 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3501 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3502 | } |
| 3503 | } |
| 3504 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3505 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3506 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3507 | * @hide |
| 3508 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3509 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3510 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3514 | * @hide |
| 3515 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3516 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3517 | if (mService != null) { |
| 3518 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3519 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3520 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3521 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3522 | } |
| 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | /** |
| 3527 | * @hide |
| 3528 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 3529 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3530 | if (mService != null) { |
| 3531 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 3532 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3533 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3534 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3535 | } |
| 3536 | } |
| 3537 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3538 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3539 | /** |
| 3540 | * @hide |
| 3541 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3542 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3543 | if (mService != null) { |
| 3544 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3545 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3547 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3551 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3552 | /** |
| 3553 | * @hide |
| 3554 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3555 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3556 | if (mService != null) { |
| 3557 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3558 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3559 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3560 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3564 | |
| 3565 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3566 | * @hide |
| 3567 | */ |
| 3568 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3569 | if (mService != null) { |
| 3570 | try { |
| 3571 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3572 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3573 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | /** |
| 3579 | * @hide |
| 3580 | */ |
| 3581 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3582 | if (mService != null) { |
| 3583 | try { |
| 3584 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3585 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3586 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3592 | * Should be called when keyguard has been dismissed. |
| 3593 | * @hide |
| 3594 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3595 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3596 | if (mService != null) { |
| 3597 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3598 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3599 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3600 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | /** |
| 3606 | * Should be called when keyguard view has been shown to the user. |
| 3607 | * @hide |
| 3608 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3609 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3610 | if (mService != null) { |
| 3611 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3612 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3613 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3614 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3615 | } |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3620 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3621 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3622 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3623 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3624 | * @return whether the package was successfully registered as the device owner. |
| 3625 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3626 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3627 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3628 | public boolean setDeviceOwner(ComponentName who) { |
| 3629 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | /** |
| 3633 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3634 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3635 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3636 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | /** |
| 3640 | * @hide |
| 3641 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3642 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3643 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | /** |
| 3647 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3648 | * Sets the given package as the device owner. The package must already be installed. There |
| 3649 | * must not already be a device owner. |
| 3650 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3651 | * this method. |
| 3652 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3653 | * 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] | 3654 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3655 | * @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] | 3656 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3657 | * @return whether the package was successfully registered as the device owner. |
| 3658 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3659 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3660 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3661 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3662 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3663 | if (mService != null) { |
| 3664 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3665 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3666 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3667 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3668 | } |
| 3669 | } |
| 3670 | return false; |
| 3671 | } |
| 3672 | |
| 3673 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3674 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3675 | * 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] | 3676 | * 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] | 3677 | * package is currently registered as the device owner app, pass in the package name from |
| 3678 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3679 | * 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] | 3680 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3681 | * the setup process. |
| 3682 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3683 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3684 | * @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] | 3685 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3686 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3687 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3688 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3689 | } |
| 3690 | |
| 3691 | /** |
| 3692 | * @return true if a package is registered as device owner, only when it's running on the |
| 3693 | * calling user. |
| 3694 | * |
| 3695 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3696 | * @hide |
| 3697 | */ |
| 3698 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3699 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3700 | } |
| 3701 | |
| 3702 | /** |
| 3703 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3704 | * user. |
| 3705 | * |
| 3706 | * <p>Requires the MANAGE_USERS permission. |
| 3707 | * |
| 3708 | * @hide |
| 3709 | */ |
| 3710 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3711 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3712 | } |
| 3713 | |
| 3714 | /** |
| 3715 | * @return device owner component name, only when it's running on the calling user. |
| 3716 | * |
| 3717 | * @hide |
| 3718 | */ |
| 3719 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3720 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3721 | } |
| 3722 | |
| 3723 | /** |
| 3724 | * @return device owner component name, even if it's running on a different user. |
| 3725 | * |
| 3726 | * <p>Requires the MANAGE_USERS permission. |
| 3727 | * |
| 3728 | * @hide |
| 3729 | */ |
| 3730 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3731 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3732 | } |
| 3733 | |
| 3734 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3735 | if (packageName == null) { |
| 3736 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3737 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3738 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3739 | if (deviceOwner == null) { |
| 3740 | return false; |
| 3741 | } |
| 3742 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3745 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3746 | if (mService != null) { |
| 3747 | try { |
| 3748 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3749 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3750 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3751 | } |
| 3752 | } |
| 3753 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3756 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3757 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3758 | * no device owner. |
| 3759 | * |
| 3760 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3761 | * |
| 3762 | * @hide |
| 3763 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3764 | public int getDeviceOwnerUserId() { |
| 3765 | if (mService != null) { |
| 3766 | try { |
| 3767 | return mService.getDeviceOwnerUserId(); |
| 3768 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3769 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3770 | } |
| 3771 | } |
| 3772 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3776 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 3777 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 3778 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3779 | * |
| 3780 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3781 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 3782 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3783 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3784 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3785 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3786 | if (mService != null) { |
| 3787 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3788 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3789 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3790 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3791 | } |
| 3792 | } |
| 3793 | } |
| 3794 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3795 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3796 | * Returns the device owner package name, only if it's running on the calling user. |
| 3797 | * |
| 3798 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3799 | * |
| 3800 | * @hide |
| 3801 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3802 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3803 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3804 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3805 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3806 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3810 | * @return true if the device is managed by any device owner. |
| 3811 | * |
| 3812 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3813 | * |
| 3814 | * @hide |
| 3815 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3816 | public boolean isDeviceManaged() { |
| 3817 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * Returns the device owner name. Note this method *will* return the device owner |
| 3822 | * name when it's running on a different user. |
| 3823 | * |
| 3824 | * <p>Requires the MANAGE_USERS permission. |
| 3825 | * |
| 3826 | * @hide |
| 3827 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3828 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3829 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3830 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3831 | if (mService != null) { |
| 3832 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3833 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3834 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3835 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3836 | } |
| 3837 | } |
| 3838 | return null; |
| 3839 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3840 | |
| 3841 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3842 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3843 | * @deprecated Do not use |
| 3844 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3845 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3846 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3847 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3848 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3849 | return null; |
| 3850 | } |
| 3851 | |
| 3852 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3853 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3854 | * @deprecated Do not use |
| 3855 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3856 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3857 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3858 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3859 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3860 | return null; |
| 3861 | } |
| 3862 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3863 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3864 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3865 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3866 | * Sets the given component as an active admin and registers the package as the profile |
| 3867 | * owner for this user. The package must already be installed and there shouldn't be |
| 3868 | * an existing profile owner registered for this user. Also, this method must be called |
| 3869 | * before the user setup has been completed. |
| 3870 | * <p> |
| 3871 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3872 | * MANAGE_DEVICE_ADMINS permission. |
| 3873 | * @param admin The component to register as an active admin and profile owner. |
| 3874 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3875 | * @return whether the admin was successfully registered as the profile owner. |
| 3876 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3877 | * the user has already been set up. |
| 3878 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3879 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3880 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3881 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3882 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3883 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3884 | if (mService != null) { |
| 3885 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3886 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3887 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3888 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3889 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3890 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | return false; |
| 3894 | } |
| 3895 | |
| 3896 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3897 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 3898 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 3899 | * will be thrown. |
| 3900 | * <p> |
| 3901 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3902 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3903 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3904 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3905 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3906 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3907 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3908 | if (mService != null) { |
| 3909 | try { |
| 3910 | mService.clearProfileOwner(admin); |
| 3911 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3912 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3913 | } |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3918 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3919 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3920 | */ |
| 3921 | public boolean hasUserSetupCompleted() { |
| 3922 | if (mService != null) { |
| 3923 | try { |
| 3924 | return mService.hasUserSetupCompleted(); |
| 3925 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3926 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | return true; |
| 3930 | } |
| 3931 | |
| 3932 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3933 | * @hide |
| 3934 | * 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] | 3935 | * already be installed. There must not already be a profile owner for this user. |
| 3936 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3937 | * this method. |
| 3938 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3939 | * - the caller is SYSTEM_UID. |
| 3940 | * - 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] | 3941 | * @param admin the component name to be registered as profile owner. |
| 3942 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3943 | * @param userHandle the userId to set the profile owner for. |
| 3944 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3945 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3946 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3947 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3948 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3949 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3950 | if (mService != null) { |
| 3951 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3952 | if (ownerName == null) { |
| 3953 | ownerName = ""; |
| 3954 | } |
| 3955 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3956 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3957 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3958 | } |
| 3959 | } |
| 3960 | return false; |
| 3961 | } |
| 3962 | |
| 3963 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3964 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3965 | * <p> |
| 3966 | * 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] | 3967 | * 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] | 3968 | * <p> |
| 3969 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 3970 | * will be blank and the user will not be allowed to change it. |
| 3971 | * <p> |
| 3972 | * 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] | 3973 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3974 | * and set a new version of this string accordingly. |
| 3975 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3976 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3977 | * @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] | 3978 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3979 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3980 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3981 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3982 | if (mService != null) { |
| 3983 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3984 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3985 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3986 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3987 | } |
| 3988 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | /** |
| 3992 | * @return The device owner information. If it is not set returns {@code null}. |
| 3993 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3994 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3995 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3996 | if (mService != null) { |
| 3997 | try { |
| 3998 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3999 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4000 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4001 | } |
| 4002 | } |
| 4003 | return null; |
| 4004 | } |
| 4005 | |
| 4006 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4007 | * Called by device or profile owners to suspend packages for this user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4008 | * <p> |
| 4009 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4010 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4011 | * device. |
| 4012 | * <p> |
| 4013 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4014 | * 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] | 4015 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4016 | * |
| 4017 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4018 | * @param packageNames The package names to suspend or unsuspend. |
| 4019 | * @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] | 4020 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4021 | * @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] | 4022 | * this method. |
| 4023 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4024 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4025 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4026 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4027 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4028 | if (mService != null) { |
| 4029 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4030 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4031 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4032 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4033 | } |
| 4034 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4035 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | /** |
| 4039 | * Called by device or profile owners to determine if a package is suspended. |
| 4040 | * |
| 4041 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4042 | * @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] | 4043 | * @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] | 4044 | * suspended, could not be found or an error occurred. |
| 4045 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4046 | * @throws NameNotFoundException if the package could not be found. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4047 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4048 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4049 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4050 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4051 | if (mService != null) { |
| 4052 | try { |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4053 | return mService.isPackageSuspended(admin, packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4054 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4055 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4056 | } catch (IllegalArgumentException ex) { |
| 4057 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4058 | } |
| 4059 | } |
| 4060 | return false; |
| 4061 | } |
| 4062 | |
| 4063 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4064 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4065 | * be used. Only the profile owner can call this. |
| 4066 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4067 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4068 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4069 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4070 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4071 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4072 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4073 | if (mService != null) { |
| 4074 | try { |
| 4075 | mService.setProfileEnabled(admin); |
| 4076 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4077 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4078 | } |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4083 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4084 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4085 | * 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] | 4086 | * |
| 4087 | * @see #isProfileOwnerApp |
| 4088 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4089 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4090 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4091 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4092 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4093 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4094 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4095 | if (mService != null) { |
| 4096 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4097 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4098 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4099 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4100 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4101 | } |
| 4102 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4103 | |
| 4104 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4105 | * 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] | 4106 | * 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] | 4107 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4108 | * |
| 4109 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4110 | * @return Whether or not the package is registered as the profile owner. |
| 4111 | */ |
| 4112 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4113 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4114 | if (mService != null) { |
| 4115 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4116 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4117 | return profileOwner != null |
| 4118 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4119 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4120 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | return false; |
| 4124 | } |
| 4125 | |
| 4126 | /** |
| 4127 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4128 | * @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] | 4129 | * owner has been set for that user. |
| 4130 | * @throws IllegalArgumentException if the userId is invalid. |
| 4131 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4132 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4133 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4134 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4135 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4136 | } |
| 4137 | |
| 4138 | /** |
| 4139 | * @see #getProfileOwner() |
| 4140 | * @hide |
| 4141 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4142 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4143 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4144 | if (mService != null) { |
| 4145 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4146 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4147 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4148 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4149 | } |
| 4150 | } |
| 4151 | return null; |
| 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4156 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4157 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4158 | * @throws IllegalArgumentException if the userId is invalid. |
| 4159 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4160 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4161 | if (mService != null) { |
| 4162 | try { |
| 4163 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4164 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4165 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4166 | } |
| 4167 | } |
| 4168 | return null; |
| 4169 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4170 | |
| 4171 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4172 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4173 | * @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] | 4174 | * @return the human readable name of the organisation associated with this profile owner or |
| 4175 | * null if one is not set. |
| 4176 | * @throws IllegalArgumentException if the userId is invalid. |
| 4177 | */ |
| 4178 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4179 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4180 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4181 | if (mService != null) { |
| 4182 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 4183 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4184 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4185 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4186 | } |
| 4187 | } |
| 4188 | return null; |
| 4189 | } |
| 4190 | |
| 4191 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4192 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 4193 | * 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] | 4194 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 4195 | * intent preferences are reset. |
| 4196 | * <p> |
| 4197 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 4198 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 4199 | * the filter. |
| 4200 | * <p> |
| 4201 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 4202 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4203 | * |
| 4204 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4205 | * @param filter The IntentFilter for which a default handler is added. |
| 4206 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4207 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4208 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4209 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 4210 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4211 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4212 | if (mService != null) { |
| 4213 | try { |
| 4214 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4215 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4216 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | } |
| 4220 | |
| 4221 | /** |
| 4222 | * 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] | 4223 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4224 | * <p> |
| 4225 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4226 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4227 | * |
| 4228 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4229 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4230 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4231 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4232 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4233 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4234 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4235 | if (mService != null) { |
| 4236 | try { |
| 4237 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4238 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4239 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4240 | } |
| 4241 | } |
| 4242 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4243 | |
| 4244 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4245 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4246 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4247 | * {@link #getApplicationRestrictions}. |
| 4248 | * <p> |
| 4249 | * This permission is persistent until it is later cleared by calling this method with a |
| 4250 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4251 | * <p> |
| 4252 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4253 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4254 | * |
| 4255 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4256 | * @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] | 4257 | * APIs. If {@code null} is given the current package will be cleared. |
| 4258 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4259 | * @throws NameNotFoundException if {@code packageName} is not found |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4260 | */ |
| 4261 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4262 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4263 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4264 | if (mService != null) { |
| 4265 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4266 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4267 | throw new NameNotFoundException(packageName); |
| 4268 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4269 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4270 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4271 | } |
| 4272 | } |
| 4273 | } |
| 4274 | |
| 4275 | /** |
| 4276 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 4277 | * package for the current user, or {@code null} if none is set. |
| 4278 | * |
| 4279 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4280 | * @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] | 4281 | * {@code null} if none is set. |
| 4282 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4283 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4284 | public @Nullable String getApplicationRestrictionsManagingPackage( |
| 4285 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4286 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4287 | if (mService != null) { |
| 4288 | try { |
| 4289 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4290 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4291 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4292 | } |
| 4293 | } |
| 4294 | return null; |
| 4295 | } |
| 4296 | |
| 4297 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4298 | * Called by any application to find out whether it has been granted permission via |
| 4299 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4300 | * for the calling user. |
| 4301 | * |
| 4302 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4303 | * that method. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4304 | */ |
| 4305 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4306 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4307 | if (mService != null) { |
| 4308 | try { |
| 4309 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 4310 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4311 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4312 | } |
| 4313 | } |
| 4314 | return false; |
| 4315 | } |
| 4316 | |
| 4317 | /** |
| 4318 | * 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] | 4319 | * <p> |
| 4320 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4321 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4322 | * security exception will be thrown. |
| 4323 | * <p> |
| 4324 | * 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] | 4325 | * <ul> |
| 4326 | * <li>{@code boolean} |
| 4327 | * <li>{@code int} |
| 4328 | * <li>{@code String} or {@code String[]} |
| 4329 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4330 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4331 | * <p> |
| 4332 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 4333 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4334 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4335 | * <p> |
| 4336 | * The application restrictions are only made visible to the target application via |
| 4337 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 4338 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4339 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4340 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4341 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 4342 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4343 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4344 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4345 | * @param packageName The name of the package to update restricted settings for. |
| 4346 | * @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] | 4347 | * set of active restrictions. |
| 4348 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4349 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4350 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4351 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4352 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4353 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4354 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4355 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4356 | if (mService != null) { |
| 4357 | try { |
| 4358 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 4359 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4360 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4361 | } |
| 4362 | } |
| 4363 | } |
| 4364 | |
| 4365 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4366 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 4367 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 4368 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4369 | * {@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] | 4370 | * <p> |
| 4371 | * The calling device admin must have requested |
| 4372 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4373 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4374 | * <p> |
| 4375 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4376 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 4377 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4378 | * |
| 4379 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4380 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4381 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 4382 | * strictly disabled according to the state of the |
| 4383 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4384 | * <p> |
| 4385 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 4386 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 4387 | * device admins. |
| 4388 | * <p> |
| 4389 | * Consult documentation for the specific TrustAgent to determine legal options |
| 4390 | * parameters. |
| 4391 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4392 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4393 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4394 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4395 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4396 | if (mService != null) { |
| 4397 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4398 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4399 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4400 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4401 | } |
| 4402 | } |
| 4403 | } |
| 4404 | |
| 4405 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4406 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4407 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4408 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4409 | * <p> |
| 4410 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4411 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 4412 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4413 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4414 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4415 | * this function returns a list of configurations for all admins that declare |
| 4416 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4417 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4418 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4419 | * 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] | 4420 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4421 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4422 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4423 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 4424 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4425 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4429 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 4430 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4431 | if (mService != null) { |
| 4432 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4433 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 4434 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4435 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4436 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4437 | } |
| 4438 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4439 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4443 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 4444 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4445 | * <p> |
| 4446 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4447 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4448 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4449 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4450 | * @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] | 4451 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4452 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4453 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4454 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4455 | if (mService != null) { |
| 4456 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4457 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4458 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4459 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4460 | } |
| 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4465 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4466 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4467 | * <p> |
| 4468 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4469 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4470 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4471 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4472 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4473 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4474 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4475 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4476 | if (mService != null) { |
| 4477 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4478 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4479 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4480 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | return false; |
| 4484 | } |
| 4485 | |
| 4486 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4487 | * Determine whether or not caller-Id information has been disabled. |
| 4488 | * |
| 4489 | * @param userHandle The user for whom to check the caller-id permission |
| 4490 | * @hide |
| 4491 | */ |
| 4492 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4493 | if (mService != null) { |
| 4494 | try { |
| 4495 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4496 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4497 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4498 | } |
| 4499 | } |
| 4500 | return false; |
| 4501 | } |
| 4502 | |
| 4503 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4504 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 4505 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4506 | * <p> |
| 4507 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4508 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4509 | * |
| 4510 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4511 | * @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] | 4512 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4513 | */ |
| 4514 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4515 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4516 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4517 | if (mService != null) { |
| 4518 | try { |
| 4519 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 4520 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4521 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4522 | } |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | /** |
| 4527 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4528 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4529 | * <p> |
| 4530 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4531 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4532 | * |
| 4533 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4534 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4535 | */ |
| 4536 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4537 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4538 | if (mService != null) { |
| 4539 | try { |
| 4540 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4541 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4542 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4543 | } |
| 4544 | } |
| 4545 | return false; |
| 4546 | } |
| 4547 | |
| 4548 | |
| 4549 | /** |
| 4550 | * Determine whether or not contacts search has been disabled. |
| 4551 | * |
| 4552 | * @param userHandle The user for whom to check the contacts search permission |
| 4553 | * @hide |
| 4554 | */ |
| 4555 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4556 | if (mService != null) { |
| 4557 | try { |
| 4558 | return mService |
| 4559 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4560 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4561 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | return false; |
| 4565 | } |
| 4566 | |
| 4567 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4568 | * 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] | 4569 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4570 | * @hide |
| 4571 | */ |
| 4572 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4573 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4574 | if (mService != null) { |
| 4575 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4576 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 4577 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4578 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4579 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4580 | } |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4585 | * 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] | 4586 | * @hide |
| 4587 | */ |
| 4588 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4589 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4590 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4591 | originalIntent); |
| 4592 | } |
| 4593 | |
| 4594 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4595 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 4596 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4597 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4598 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4599 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4600 | * <p> |
| 4601 | * This API works on managed profile only. |
| 4602 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4603 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4604 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 4605 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4606 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4607 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4608 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4609 | if (mService != null) { |
| 4610 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4611 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4612 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4613 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4614 | } |
| 4615 | } |
| 4616 | } |
| 4617 | |
| 4618 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4619 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 4620 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4621 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4622 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4623 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4624 | * <p> |
| 4625 | * This API works on managed profile only. |
| 4626 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4627 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4628 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4629 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4630 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4631 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4632 | if (mService != null) { |
| 4633 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4634 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4635 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4636 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | return true; |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4644 | * <p> |
| 4645 | * This API works on managed profile UserHandle only. |
| 4646 | * |
| 4647 | * @param userHandle The user for whom to check the caller-id permission |
| 4648 | * @hide |
| 4649 | */ |
| 4650 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4651 | if (mService != null) { |
| 4652 | try { |
| 4653 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4654 | .getIdentifier()); |
| 4655 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4656 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4657 | } |
| 4658 | } |
| 4659 | return true; |
| 4660 | } |
| 4661 | |
| 4662 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4663 | * 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] | 4664 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 4665 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4666 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4667 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4668 | * @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] | 4669 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4670 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4671 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 4672 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4673 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4674 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4675 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4676 | if (mService != null) { |
| 4677 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4678 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4679 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4680 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4681 | } |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4686 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4687 | * 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] | 4688 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4689 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4690 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4691 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4692 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4693 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4694 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4695 | if (mService != null) { |
| 4696 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4697 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4698 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4699 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4705 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 4706 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4707 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 4708 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 4709 | * the list and not part of the system can not be enabled by the user. |
| 4710 | * <p> |
| 4711 | * Calling with a null value for the list disables the restriction so that all services can be |
| 4712 | * used, calling with an empty list only allows the builtin system's services. |
| 4713 | * <p> |
| 4714 | * System accesibility services are always available to the user the list can't modify this. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4715 | * |
| 4716 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4717 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4718 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 4719 | * accessibility services enabled, that are not in the list. |
| 4720 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4721 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4722 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4723 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4724 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4725 | if (mService != null) { |
| 4726 | try { |
| 4727 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4728 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4729 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4730 | } |
| 4731 | } |
| 4732 | return false; |
| 4733 | } |
| 4734 | |
| 4735 | /** |
| 4736 | * 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] | 4737 | * <p> |
| 4738 | * An empty list means no accessibility services except system services are allowed. Null means |
| 4739 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4740 | * |
| 4741 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4742 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4743 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4744 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4745 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4746 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4747 | if (mService != null) { |
| 4748 | try { |
| 4749 | return mService.getPermittedAccessibilityServices(admin); |
| 4750 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4751 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4752 | } |
| 4753 | } |
| 4754 | return null; |
| 4755 | } |
| 4756 | |
| 4757 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4758 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4759 | * |
| 4760 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4761 | * @param packageName Accessibility service package name that needs to be checked. |
| 4762 | * @param userHandle user id the admin is running as. |
| 4763 | * @return true if the accessibility service is permitted, otherwise false. |
| 4764 | * |
| 4765 | * @hide |
| 4766 | */ |
| 4767 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4768 | @NonNull String packageName, int userHandle) { |
| 4769 | if (mService != null) { |
| 4770 | try { |
| 4771 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4772 | userHandle); |
| 4773 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4774 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
| 4780 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4781 | * Returns the list of accessibility services permitted by the device or profiles |
| 4782 | * owners of this user. |
| 4783 | * |
| 4784 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4785 | * it will contain the intersection of the permitted lists for any device or profile |
| 4786 | * owners that apply to this user. It will also include any system accessibility services. |
| 4787 | * |
| 4788 | * @param userId which user to check for. |
| 4789 | * @return List of accessiblity service package names. |
| 4790 | * @hide |
| 4791 | */ |
| 4792 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4793 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4794 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4795 | if (mService != null) { |
| 4796 | try { |
| 4797 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4798 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4799 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4800 | } |
| 4801 | } |
| 4802 | return null; |
| 4803 | } |
| 4804 | |
| 4805 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4806 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 4807 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4808 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 4809 | * When zero or more packages have been added, input method that are not in the list and not |
| 4810 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 4811 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 4812 | * <p> |
| 4813 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 4814 | * be used, calling with an empty list disables all but the system's own input methods. |
| 4815 | * <p> |
| 4816 | * 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] | 4817 | * |
| 4818 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4819 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4820 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 4821 | * non-system input methods currently enabled that are not in the packageNames list. |
| 4822 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4823 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4824 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4825 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4826 | if (mService != null) { |
| 4827 | try { |
| 4828 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4829 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4830 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4831 | } |
| 4832 | } |
| 4833 | return false; |
| 4834 | } |
| 4835 | |
| 4836 | |
| 4837 | /** |
| 4838 | * 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] | 4839 | * <p> |
| 4840 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 4841 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4842 | * |
| 4843 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4844 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4845 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4846 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4847 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4848 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4849 | if (mService != null) { |
| 4850 | try { |
| 4851 | return mService.getPermittedInputMethods(admin); |
| 4852 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4853 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | return null; |
| 4857 | } |
| 4858 | |
| 4859 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4860 | * Called by the system to check if a specific input method is disabled by admin. |
| 4861 | * |
| 4862 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4863 | * @param packageName Input method package name that needs to be checked. |
| 4864 | * @param userHandle user id the admin is running as. |
| 4865 | * @return true if the input method is permitted, otherwise false. |
| 4866 | * |
| 4867 | * @hide |
| 4868 | */ |
| 4869 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4870 | @NonNull String packageName, int userHandle) { |
| 4871 | if (mService != null) { |
| 4872 | try { |
| 4873 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4874 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4875 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4876 | } |
| 4877 | } |
| 4878 | return false; |
| 4879 | } |
| 4880 | |
| 4881 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4882 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4883 | * 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] | 4884 | * |
| 4885 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4886 | * it will contain the intersection of the permitted lists for any device or profile |
| 4887 | * owners that apply to this user. It will also include any system input methods. |
| 4888 | * |
| 4889 | * @return List of input method package names. |
| 4890 | * @hide |
| 4891 | */ |
| 4892 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4893 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4894 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4895 | if (mService != null) { |
| 4896 | try { |
| 4897 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4898 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4899 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4900 | } |
| 4901 | } |
| 4902 | return null; |
| 4903 | } |
| 4904 | |
| 4905 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4906 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4907 | * currently installed it. |
| 4908 | * |
| 4909 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4910 | * |
| 4911 | * @return List of package names to keep cached. |
| 4912 | * @hide |
| 4913 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4914 | public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4915 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4916 | if (mService != null) { |
| 4917 | try { |
| 4918 | return mService.getKeepUninstalledPackages(admin); |
| 4919 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4920 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4921 | } |
| 4922 | } |
| 4923 | return null; |
| 4924 | } |
| 4925 | |
| 4926 | /** |
| 4927 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4928 | * currently installed it. |
| 4929 | * |
| 4930 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4931 | * automatically pre-cached.</p> |
| 4932 | * |
| 4933 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4934 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4935 | * @throws SecurityException if {@code admin} is not a device owner. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4936 | * @hide |
| 4937 | */ |
| 4938 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4939 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4940 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4941 | if (mService != null) { |
| 4942 | try { |
| 4943 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4944 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4945 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4946 | } |
| 4947 | } |
| 4948 | } |
| 4949 | |
| 4950 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4951 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4952 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4953 | * created. If you need to persist an identifier for this user, use |
| 4954 | * {@link UserManager#getSerialNumberForUser}. |
| 4955 | * |
| 4956 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4957 | * @param name the user's name |
| 4958 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4959 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4960 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4961 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4962 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4963 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4964 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4965 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4966 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4967 | return null; |
| 4968 | } |
| 4969 | |
| 4970 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4971 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4972 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4973 | * created. If you need to persist an identifier for this user, use |
| 4974 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4975 | * immediately. |
| 4976 | * |
| 4977 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4978 | * as registered as an active admin on the new user. The profile owner package will be |
| 4979 | * installed on the new user if it already is installed on the device. |
| 4980 | * |
| 4981 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4982 | * profileOwnerComponent when onEnable is called. |
| 4983 | * |
| 4984 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4985 | * @param name the user's name |
| 4986 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4987 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4988 | * the user. |
| 4989 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4990 | * on the new user. |
| 4991 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4992 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4993 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4994 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4995 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4996 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4997 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4998 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4999 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5000 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5001 | return null; |
| 5002 | } |
| 5003 | |
| 5004 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5005 | * 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] | 5006 | */ |
| 5007 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5008 | |
| 5009 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5010 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5011 | * ephemeral. |
| 5012 | * @hide |
| 5013 | */ |
| 5014 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5015 | |
| 5016 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5017 | * Called by a device owner to create a user with the specified name and a given component of |
| 5018 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5019 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5020 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5021 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5022 | * <p> |
| 5023 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5024 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5025 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5026 | * on the new user. |
| 5027 | * <p> |
| 5028 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5029 | * 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] | 5030 | * |
| 5031 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5032 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5033 | * @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] | 5034 | * same package as admin, otherwise no user is created and an |
| 5035 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5036 | * @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] | 5037 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5038 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5039 | * @see UserHandle |
| 5040 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5041 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5042 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5043 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5044 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5045 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5046 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5047 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5048 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5049 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5050 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5051 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5052 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5053 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5057 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5058 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5059 | * |
| 5060 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5061 | * @param userHandle the user to remove. |
| 5062 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5063 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5064 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5065 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5066 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5067 | try { |
| 5068 | return mService.removeUser(admin, userHandle); |
| 5069 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5070 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5075 | * Called by a device owner to switch the specified user to the foreground. |
| 5076 | * |
| 5077 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5078 | * @param userHandle the user to switch to; null will switch to primary. |
| 5079 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5080 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5081 | * @see Intent#ACTION_USER_FOREGROUND |
| 5082 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5083 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5084 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5085 | try { |
| 5086 | return mService.switchUser(admin, userHandle); |
| 5087 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5088 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5093 | * Retrieves the application restrictions for a given target application running in the calling |
| 5094 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5095 | * <p> |
| 5096 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 5097 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 5098 | * security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5099 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5100 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5101 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5102 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5103 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5104 | * @param packageName The name of the package to fetch restricted settings of. |
| 5105 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5106 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 5107 | * {@link Bundle} if no restrictions have been set. |
| 5108 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5109 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5110 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5111 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5112 | public @NonNull Bundle getApplicationRestrictions( |
| 5113 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5114 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5115 | if (mService != null) { |
| 5116 | try { |
| 5117 | return mService.getApplicationRestrictions(admin, packageName); |
| 5118 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5119 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5120 | } |
| 5121 | } |
| 5122 | return null; |
| 5123 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5124 | |
| 5125 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5126 | * 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] | 5127 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5128 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5129 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5130 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5131 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5132 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5133 | * for the list of keys. |
| 5134 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5135 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5136 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5137 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5138 | if (mService != null) { |
| 5139 | try { |
| 5140 | mService.setUserRestriction(admin, key, true); |
| 5141 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5142 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5143 | } |
| 5144 | } |
| 5145 | } |
| 5146 | |
| 5147 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5148 | * 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] | 5149 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5150 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5151 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5152 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5153 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5154 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5155 | * for the list of keys. |
| 5156 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5157 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5158 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5159 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5160 | if (mService != null) { |
| 5161 | try { |
| 5162 | mService.setUserRestriction(admin, key, false); |
| 5163 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5164 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5165 | } |
| 5166 | } |
| 5167 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 5168 | |
| 5169 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5170 | * Called by a profile or device owner to get user restrictions set with |
| 5171 | * {@link #addUserRestriction(ComponentName, String)}. |
| 5172 | * <p> |
| 5173 | * 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] | 5174 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5175 | * {@link UserManager#getUserRestrictions()}. |
| 5176 | * |
| 5177 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5178 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5179 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5180 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5181 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5182 | Bundle ret = null; |
| 5183 | if (mService != null) { |
| 5184 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 5185 | ret = mService.getUserRestrictions(admin); |
| 5186 | } catch (RemoteException e) { |
| 5187 | throw e.rethrowFromSystemServer(); |
| 5188 | } |
| 5189 | } |
| 5190 | return ret == null ? new Bundle() : ret; |
| 5191 | } |
| 5192 | |
| 5193 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5194 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it is |
| 5195 | * unavailable for use, but the data and actual package file remain. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5196 | * |
| 5197 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5198 | * @param packageName The name of the package to hide or unhide. |
| 5199 | * @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] | 5200 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5201 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5202 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5203 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5204 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5205 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5206 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5207 | if (mService != null) { |
| 5208 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5209 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5210 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5211 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5212 | } |
| 5213 | } |
| 5214 | return false; |
| 5215 | } |
| 5216 | |
| 5217 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5218 | * Called by profile or device owners to determine if a package is hidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5219 | * |
| 5220 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5221 | * @param packageName The name of the package to retrieve the hidden status of. |
| 5222 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5223 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5224 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5225 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5226 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5227 | if (mService != null) { |
| 5228 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5229 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5230 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5231 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5232 | } |
| 5233 | } |
| 5234 | return false; |
| 5235 | } |
| 5236 | |
| 5237 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5238 | * Called by profile or device owners to re-enable a system app that was disabled by default |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5239 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5240 | * |
| 5241 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5242 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5243 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5244 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5245 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5246 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5247 | if (mService != null) { |
| 5248 | try { |
| 5249 | mService.enableSystemApp(admin, packageName); |
| 5250 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5251 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5252 | } |
| 5253 | } |
| 5254 | } |
| 5255 | |
| 5256 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5257 | * Called by profile or device owners to re-enable system apps by intent that were disabled by |
| 5258 | * default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5259 | * |
| 5260 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5261 | * @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] | 5262 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5263 | * @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] | 5264 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5265 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5266 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5267 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5268 | if (mService != null) { |
| 5269 | try { |
| 5270 | return mService.enableSystemAppWithIntent(admin, intent); |
| 5271 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5272 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5273 | } |
| 5274 | } |
| 5275 | return 0; |
| 5276 | } |
| 5277 | |
| 5278 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 5279 | * Called by a device owner or profile owner to disable account management for a specific type |
| 5280 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5281 | * <p> |
| 5282 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 5283 | * exception will be thrown. |
| 5284 | * <p> |
| 5285 | * When account management is disabled for an account type, adding or removing an account of |
| 5286 | * that type will not be possible. |
| 5287 | * <p> |
| 5288 | * 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] | 5289 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 5290 | * management for a specific type is disabled. |
| 5291 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5292 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5293 | * @param accountType For which account management is disabled or enabled. |
| 5294 | * @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] | 5295 | * enabled (false). |
| 5296 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5297 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5298 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5299 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5300 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5301 | if (mService != null) { |
| 5302 | try { |
| 5303 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 5304 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5305 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5311 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 5312 | * |
| 5313 | * <p> Account management can be disabled/enabled by calling |
| 5314 | * {@link #setAccountManagementDisabled}. |
| 5315 | * |
| 5316 | * @return a list of account types for which account management has been disabled. |
| 5317 | * |
| 5318 | * @see #setAccountManagementDisabled |
| 5319 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5320 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5321 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5322 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | /** |
| 5326 | * @see #getAccountTypesWithManagementDisabled() |
| 5327 | * @hide |
| 5328 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5329 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5330 | if (mService != null) { |
| 5331 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5332 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5333 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5334 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | return null; |
| 5339 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5340 | |
| 5341 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5342 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5343 | * <p> |
| 5344 | * Any packages that shares uid with an allowed package will also be allowed to activate lock |
| 5345 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
| 5346 | * package list results in locked tasks belonging to those packages to be finished. This |
| 5347 | * function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5348 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5349 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [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 owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5352 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 5353 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 5354 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 5355 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5356 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5357 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5358 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5359 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5360 | if (mService != null) { |
| 5361 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5362 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5363 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5364 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5365 | } |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5370 | * This function returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5371 | * |
| 5372 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5373 | * @hide |
| 5374 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5375 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5376 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5377 | if (mService != null) { |
| 5378 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5379 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5380 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5381 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5382 | } |
| 5383 | } |
| 5384 | return null; |
| 5385 | } |
| 5386 | |
| 5387 | /** |
| 5388 | * This function lets the caller know whether the given component is allowed to start the |
| 5389 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5390 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5391 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5392 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5393 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5394 | if (mService != null) { |
| 5395 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5396 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5397 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5398 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5399 | } |
| 5400 | } |
| 5401 | return false; |
| 5402 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5403 | |
| 5404 | /** |
| 5405 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 5406 | * 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] | 5407 | * <p> |
| 5408 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5409 | * <ul> |
| 5410 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 5411 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 5412 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5413 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5414 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5415 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5416 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 5417 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 5418 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 5419 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 5420 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5421 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5422 | * <p> |
| 5423 | * 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] | 5424 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5425 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 5426 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5427 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5428 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5429 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 5430 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5431 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5432 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 5433 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5434 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5435 | * |
| 5436 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5437 | * @param setting The name of the setting to update. |
| 5438 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5439 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5440 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5441 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5442 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5443 | if (mService != null) { |
| 5444 | try { |
| 5445 | mService.setGlobalSetting(admin, setting, value); |
| 5446 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5447 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5448 | } |
| 5449 | } |
| 5450 | } |
| 5451 | |
| 5452 | /** |
| 5453 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5454 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5455 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5456 | * <p> |
| 5457 | * 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] | 5458 | * <ul> |
| 5459 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5460 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5461 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5462 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5463 | * <p> |
| 5464 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5465 | * <ul> |
| 5466 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5467 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5468 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5469 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5470 | * @param setting The name of the setting to update. |
| 5471 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5472 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5473 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5474 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5475 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5476 | if (mService != null) { |
| 5477 | try { |
| 5478 | mService.setSecureSetting(admin, setting, value); |
| 5479 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5480 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5481 | } |
| 5482 | } |
| 5483 | } |
| 5484 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5485 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5486 | * Designates a specific service component as the provider for making permission requests of a |
| 5487 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5488 | * <p/> |
| 5489 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5490 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5491 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5492 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5493 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 5494 | * provider previously assigned. |
| 5495 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5496 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5497 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5498 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5499 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5500 | if (mService != null) { |
| 5501 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5502 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5503 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5504 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5505 | } |
| 5506 | } |
| 5507 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5508 | |
| 5509 | /** |
| 5510 | * 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] | 5511 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5512 | * |
| 5513 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5514 | * @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] | 5515 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5516 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5517 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5518 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5519 | if (mService != null) { |
| 5520 | try { |
| 5521 | mService.setMasterVolumeMuted(admin, on); |
| 5522 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5523 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5524 | } |
| 5525 | } |
| 5526 | } |
| 5527 | |
| 5528 | /** |
| 5529 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5530 | * |
| 5531 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5532 | * @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] | 5533 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5534 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5535 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5536 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5537 | if (mService != null) { |
| 5538 | try { |
| 5539 | return mService.isMasterVolumeMuted(admin); |
| 5540 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5541 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5542 | } |
| 5543 | } |
| 5544 | return false; |
| 5545 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5546 | |
| 5547 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5548 | * Called by profile or device owners to change whether a user can uninstall a package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5549 | * |
| 5550 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5551 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5552 | * @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] | 5553 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5554 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5555 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5556 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5557 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5558 | if (mService != null) { |
| 5559 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5560 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5561 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5562 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5563 | } |
| 5564 | } |
| 5565 | } |
| 5566 | |
| 5567 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5568 | * 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] | 5569 | * 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] | 5570 | * <p> |
| 5571 | * <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] | 5572 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 5573 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 5574 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5575 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5576 | * @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] | 5577 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5578 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5579 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5580 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5581 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5582 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5583 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5584 | if (mService != null) { |
| 5585 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 5586 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5587 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5588 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5589 | } |
| 5590 | } |
| 5591 | return false; |
| 5592 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5593 | |
| 5594 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5595 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 5596 | * package to be available in the parent profile. As a result the user will be able to add |
| 5597 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 5598 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 5599 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5600 | * <p> |
| 5601 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5602 | * |
| 5603 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5604 | * @param packageName The package from which widget providers are white-listed. |
| 5605 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5606 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5607 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5608 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5609 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5610 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5611 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5612 | if (mService != null) { |
| 5613 | try { |
| 5614 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 5615 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5616 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5617 | } |
| 5618 | } |
| 5619 | return false; |
| 5620 | } |
| 5621 | |
| 5622 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5623 | * 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] | 5624 | * package to be available in the parent profile. For this method to take effect the package |
| 5625 | * should have been added via |
| 5626 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5627 | * <p> |
| 5628 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5629 | * |
| 5630 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5631 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5632 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5633 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5634 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5635 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5636 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5637 | public boolean removeCrossProfileWidgetProvider( |
| 5638 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5639 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5640 | if (mService != null) { |
| 5641 | try { |
| 5642 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5643 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5644 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5645 | } |
| 5646 | } |
| 5647 | return false; |
| 5648 | } |
| 5649 | |
| 5650 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5651 | * 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] | 5652 | * available in the parent profile. |
| 5653 | * |
| 5654 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5655 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5656 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5657 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5658 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5659 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5660 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5661 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5662 | if (mService != null) { |
| 5663 | try { |
| 5664 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5665 | if (providers != null) { |
| 5666 | return providers; |
| 5667 | } |
| 5668 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5669 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | return Collections.emptyList(); |
| 5673 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5674 | |
| 5675 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5676 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5677 | * |
| 5678 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5679 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5680 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5681 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5682 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5683 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5684 | try { |
| 5685 | mService.setUserIcon(admin, icon); |
| 5686 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5687 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5688 | } |
| 5689 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5690 | |
| 5691 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5692 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5693 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5694 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5695 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5696 | * components in the device owner package can set system update policies and the most |
| 5697 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5698 | * @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] | 5699 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5700 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5701 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5702 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5703 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5704 | if (mService != null) { |
| 5705 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5706 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5707 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5708 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5709 | } |
| 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5714 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5715 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5716 | * @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] | 5717 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5718 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5719 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5720 | if (mService != null) { |
| 5721 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5722 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5723 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5724 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5725 | } |
| 5726 | } |
| 5727 | return null; |
| 5728 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5729 | |
| 5730 | /** |
| 5731 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5732 | * <p> |
| 5733 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 5734 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 5735 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 5736 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5737 | * |
| 5738 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5739 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5740 | * @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] | 5741 | * place. {@code true} otherwise. |
| 5742 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5743 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5744 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5745 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5746 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5747 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5748 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5749 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5750 | } |
| 5751 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5752 | |
| 5753 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5754 | * 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] | 5755 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 5756 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5757 | * |
| 5758 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5759 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5760 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 5761 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5762 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5763 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5764 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5765 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5766 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5767 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5768 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5769 | } |
| 5770 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5771 | |
| 5772 | /** |
| 5773 | * Callable by the system update service to notify device owners about pending updates. |
| 5774 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5775 | * permission. |
| 5776 | * |
| 5777 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5778 | * when the current pending update was first available. -1 if no update is available. |
| 5779 | * @hide |
| 5780 | */ |
| 5781 | @SystemApi |
| 5782 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5783 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5784 | if (mService != null) { |
| 5785 | try { |
| 5786 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5787 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5788 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5789 | } |
| 5790 | } |
| 5791 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5792 | |
| 5793 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5794 | * Called by profile or device owners to set the default response for future runtime permission |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5795 | * requests by applications. The policy can allow for normal operation which prompts the user to |
| 5796 | * grant a permission, or can allow automatic granting or denying of runtime permission requests |
| 5797 | * by an application. This also applies to new permissions declared by app updates. When a |
| 5798 | * permission is denied or granted this way, the effect is equivalent to setting the permission |
| 5799 | * grant state via {@link #setPermissionGrantState}. |
| 5800 | * <p/> |
| 5801 | * 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] | 5802 | * 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] | 5803 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5804 | * @param admin Which profile or device owner this request is associated with. |
| 5805 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5806 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 5807 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5808 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5809 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5810 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5811 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5812 | try { |
| 5813 | mService.setPermissionPolicy(admin, policy); |
| 5814 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5815 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5816 | } |
| 5817 | } |
| 5818 | |
| 5819 | /** |
| 5820 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5821 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5822 | * @param admin Which profile or device owner this request is associated with. |
| 5823 | * @return the current policy for future permission requests. |
| 5824 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5825 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5826 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5827 | try { |
| 5828 | return mService.getPermissionPolicy(admin); |
| 5829 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5830 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5835 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 5836 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 5837 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 5838 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 5839 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 5840 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5841 | * by a profile or device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5842 | * <p/> |
| 5843 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 5844 | * the permission. It retains the previous grant, if any. |
| 5845 | * <p/> |
| 5846 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5847 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5848 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5849 | * @param admin Which profile or device owner this request is associated with. |
| 5850 | * @param packageName The application to grant or revoke a permission to. |
| 5851 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5852 | * @param grantState The permission grant state which is one of |
| 5853 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5854 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5855 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5856 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5857 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5858 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5859 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5860 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5861 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5862 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5863 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5864 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5865 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5866 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5867 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5868 | } |
| 5869 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5870 | |
| 5871 | /** |
| 5872 | * Returns the current grant state of a runtime permission for a specific application. |
| 5873 | * |
| 5874 | * @param admin Which profile or device owner this request is associated with. |
| 5875 | * @param packageName The application to check the grant state for. |
| 5876 | * @param permission The permission to check for. |
| 5877 | * @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] | 5878 | * has not set a grant state, the return value is |
| 5879 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 5880 | * permission is currently granted for the package. |
| 5881 | * <p/> |
| 5882 | * If a grant state was set by the profile or device owner, then the return value will |
| 5883 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 5884 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 5885 | * currently denied or granted. |
| 5886 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5887 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5888 | * @see PackageManager#checkPermission(String, String) |
| 5889 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5890 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5891 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5892 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5893 | try { |
| 5894 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5895 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5896 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5897 | } |
| 5898 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5899 | |
| 5900 | /** |
| 5901 | * Returns if provisioning a managed profile or device is possible or not. |
| 5902 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5903 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5904 | * @return if provisioning a managed profile or device is possible or not. |
| 5905 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5906 | */ |
| 5907 | public boolean isProvisioningAllowed(String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5908 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5909 | try { |
| 5910 | return mService.isProvisioningAllowed(action); |
| 5911 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5912 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5913 | } |
| 5914 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5915 | |
| 5916 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5917 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5918 | * 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] | 5919 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5920 | * @param admin Which profile owner this request is associated with. |
| 5921 | * @return if this user is a managed profile of another user. |
| 5922 | */ |
| 5923 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5924 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5925 | try { |
| 5926 | return mService.isManagedProfile(admin); |
| 5927 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5928 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | /** |
| 5933 | * @hide |
| 5934 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5935 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5936 | * @param admin Which device owner this request is associated with. |
| 5937 | * @return if this user is a system-only user. |
| 5938 | */ |
| 5939 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5940 | try { |
| 5941 | return mService.isSystemOnlyUser(admin); |
| 5942 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5943 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5944 | } |
| 5945 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5946 | |
| 5947 | /** |
| 5948 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5949 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5950 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5951 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 5952 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5953 | * <p> |
| 5954 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5955 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5956 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5957 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5958 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5959 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5960 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5961 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5962 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5963 | } |
| 5964 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5965 | |
| 5966 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5967 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 5968 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5969 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5970 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5971 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5972 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5973 | */ |
| 5974 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5975 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5976 | try { |
| 5977 | mService.reboot(admin); |
| 5978 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5979 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5980 | } |
| 5981 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5982 | |
| 5983 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5984 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 5985 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 5986 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 5987 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 5988 | * truncated. |
| 5989 | * <p> |
| 5990 | * 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] | 5991 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5992 | * and set a new version of this string accordingly. |
| 5993 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5994 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5995 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5996 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 5997 | * existing message. |
| 5998 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5999 | */ |
| 6000 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6001 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6002 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6003 | if (mService != null) { |
| 6004 | try { |
| 6005 | mService.setShortSupportMessage(admin, message); |
| 6006 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6007 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6008 | } |
| 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | /** |
| 6013 | * Called by a device admin to get the short support message. |
| 6014 | * |
| 6015 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6016 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 6017 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6018 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6019 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6020 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6021 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6022 | if (mService != null) { |
| 6023 | try { |
| 6024 | return mService.getShortSupportMessage(admin); |
| 6025 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6026 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6027 | } |
| 6028 | } |
| 6029 | return null; |
| 6030 | } |
| 6031 | |
| 6032 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6033 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 6034 | * in the device administators settings screen. |
| 6035 | * <p> |
| 6036 | * 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] | 6037 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6038 | * and set a new version of this string accordingly. |
| 6039 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6040 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6041 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6042 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 6043 | * existing message. |
| 6044 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6045 | */ |
| 6046 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6047 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6048 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6049 | if (mService != null) { |
| 6050 | try { |
| 6051 | mService.setLongSupportMessage(admin, message); |
| 6052 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6053 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6054 | } |
| 6055 | } |
| 6056 | } |
| 6057 | |
| 6058 | /** |
| 6059 | * Called by a device admin to get the long support message. |
| 6060 | * |
| 6061 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6062 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 6063 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6064 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6065 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6066 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6067 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6068 | if (mService != null) { |
| 6069 | try { |
| 6070 | return mService.getLongSupportMessage(admin); |
| 6071 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6072 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6073 | } |
| 6074 | } |
| 6075 | return null; |
| 6076 | } |
| 6077 | |
| 6078 | /** |
| 6079 | * Called by the system to get the short support message. |
| 6080 | * |
| 6081 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6082 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6083 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6084 | * |
| 6085 | * @hide |
| 6086 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6087 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6088 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6089 | if (mService != null) { |
| 6090 | try { |
| 6091 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 6092 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6093 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6094 | } |
| 6095 | } |
| 6096 | return null; |
| 6097 | } |
| 6098 | |
| 6099 | |
| 6100 | /** |
| 6101 | * Called by the system to get the long support message. |
| 6102 | * |
| 6103 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6104 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6105 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6106 | * |
| 6107 | * @hide |
| 6108 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6109 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 6110 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6111 | if (mService != null) { |
| 6112 | try { |
| 6113 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 6114 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6115 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6116 | } |
| 6117 | } |
| 6118 | return null; |
| 6119 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6120 | |
| 6121 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6122 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 6123 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6124 | * |
| 6125 | * <p>The following methods are supported for the parent instance, all other methods will |
| 6126 | * throw a SecurityException when called on the parent instance: |
| 6127 | * <ul> |
| 6128 | * <li>{@link #getPasswordQuality}</li> |
| 6129 | * <li>{@link #setPasswordQuality}</li> |
| 6130 | * <li>{@link #getPasswordMinimumLength}</li> |
| 6131 | * <li>{@link #setPasswordMinimumLength}</li> |
| 6132 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 6133 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 6134 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 6135 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 6136 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 6137 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 6138 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 6139 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 6140 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 6141 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 6142 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 6143 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 6144 | * <li>{@link #getPasswordHistoryLength}</li> |
| 6145 | * <li>{@link #setPasswordHistoryLength}</li> |
| 6146 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 6147 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 6148 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 6149 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6150 | * <li>{@link #isActivePasswordSufficient}</li> |
| 6151 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 6152 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 6153 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 6154 | * <li>{@link #getMaximumTimeToLock}</li> |
| 6155 | * <li>{@link #setMaximumTimeToLock}</li> |
| 6156 | * <li>{@link #lockNow}</li> |
| 6157 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 6158 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 6159 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 6160 | * <li>{@link #setTrustAgentConfiguration}</li> |
| 6161 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6162 | * |
| 6163 | * @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] | 6164 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6165 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6166 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6167 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6168 | try { |
| 6169 | if (!mService.isManagedProfile(admin)) { |
| 6170 | throw new SecurityException("The current user does not have a parent profile."); |
| 6171 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6172 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6173 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6174 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6175 | } |
| 6176 | } |
| 6177 | |
| 6178 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6179 | * Called by device owner to control the security logging feature. Logging can only be |
| 6180 | * enabled on single user devices where the sole user is managed by the device owner. |
| 6181 | * |
| 6182 | * <p> Security logs contain various information intended for security auditing purposes. |
| 6183 | * See {@link SecurityEvent} for details. |
| 6184 | * |
| 6185 | * <p>There must be only one user on the device, managed by the device owner. |
| 6186 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6187 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6188 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6189 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6190 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6191 | * @see #retrieveSecurityLogs |
| 6192 | */ |
| 6193 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6194 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6195 | try { |
| 6196 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 6197 | } catch (RemoteException re) { |
| 6198 | throw re.rethrowFromSystemServer(); |
| 6199 | } |
| 6200 | } |
| 6201 | |
| 6202 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6203 | * Return whether security logging is enabled or not by the device owner. |
| 6204 | * |
| 6205 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 6206 | * thrown. |
| 6207 | * |
| 6208 | * @param admin Which device owner this request is associated with. |
| 6209 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 6210 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6211 | */ |
| 6212 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6213 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6214 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6215 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6216 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6217 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6218 | } |
| 6219 | } |
| 6220 | |
| 6221 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6222 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 6223 | * this API after device boots. |
| 6224 | * |
| 6225 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 6226 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 6227 | * |
| 6228 | * <p>There must be only one user on the device, managed by the device owner. |
| 6229 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6230 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6231 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6232 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 6233 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6234 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6235 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6236 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6237 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6238 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6239 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6240 | if (list != null) { |
| 6241 | return list.getList(); |
| 6242 | } else { |
| 6243 | // Rate limit exceeded. |
| 6244 | return null; |
| 6245 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6246 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6247 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6248 | } |
| 6249 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6250 | |
| 6251 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6252 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 6253 | * profile. |
| 6254 | * |
| 6255 | * @hide |
| 6256 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6257 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6258 | mContext.checkSelfPermission( |
| 6259 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 6260 | if (!uInfo.isManagedProfile()) { |
| 6261 | throw new SecurityException("The user " + uInfo.id |
| 6262 | + " does not have a parent profile."); |
| 6263 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6264 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6268 | * 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] | 6269 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6270 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 6271 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 6272 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 6273 | * about data corruption when parsing. </strong> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6274 | * <p> |
| 6275 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 6276 | * {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6277 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6278 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6279 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 6280 | * is not supported on the device. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6281 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6282 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6283 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 6284 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6285 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6286 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6287 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6288 | if (list != null) { |
| 6289 | return list.getList(); |
| 6290 | } else { |
| 6291 | return null; |
| 6292 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6293 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6294 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6299 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 6300 | * 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] | 6301 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6302 | * <p> |
| 6303 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6304 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 6305 | * |
| 6306 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6307 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6308 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6309 | */ |
| 6310 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6311 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6312 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6313 | // always enforce alpha channel to have 100% opacity |
| 6314 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6315 | mService.setOrganizationColor(admin, color); |
| 6316 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6317 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6322 | * @hide |
| 6323 | * |
| 6324 | * Sets the color used for customization. |
| 6325 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6326 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6327 | * @param userId which user to set the color to. |
| 6328 | * @RequiresPermission(allOf = { |
| 6329 | * Manifest.permission.MANAGE_USERS, |
| 6330 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 6331 | */ |
| 6332 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 6333 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6334 | // always enforce alpha channel to have 100% opacity |
| 6335 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6336 | mService.setOrganizationColorForUser(color, userId); |
| 6337 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6338 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6339 | } |
| 6340 | } |
| 6341 | |
| 6342 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6343 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 6344 | * This color is used as background color of the confirm credentials screen for that user. |
| 6345 | * |
| 6346 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6347 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6348 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6349 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6350 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6351 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6352 | try { |
| 6353 | return mService.getOrganizationColor(admin); |
| 6354 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6355 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6356 | } |
| 6357 | } |
| 6358 | |
| 6359 | /** |
| 6360 | * @hide |
| 6361 | * Retrieve the customization color for a given user. |
| 6362 | * |
| 6363 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6364 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6365 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6366 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6367 | try { |
| 6368 | return mService.getOrganizationColorForUser(userHandle); |
| 6369 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6370 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6371 | } |
| 6372 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6373 | |
| 6374 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6375 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 6376 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6377 | * <p> |
| 6378 | * 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] | 6379 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6380 | * and set a new version of this string accordingly. |
| 6381 | * |
| 6382 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6383 | * @param title The organization name or {@code null} to clear a previously set name. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6384 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6385 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6386 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6387 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6388 | try { |
| 6389 | mService.setOrganizationName(admin, title); |
| 6390 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6391 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6392 | } |
| 6393 | } |
| 6394 | |
| 6395 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6396 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 6397 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6398 | * |
| 6399 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6400 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6401 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6402 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6403 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6404 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6405 | try { |
| 6406 | return mService.getOrganizationName(admin); |
| 6407 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6408 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6409 | } |
| 6410 | } |
| 6411 | |
| 6412 | /** |
| 6413 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 6414 | * |
| 6415 | * @param userHandle The user id of the user we're interested in. |
| 6416 | * @return The organization name or {@code null} if none is set. |
| 6417 | * |
| 6418 | * @hide |
| 6419 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6420 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6421 | try { |
| 6422 | return mService.getOrganizationNameForUser(userHandle); |
| 6423 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6424 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6425 | } |
| 6426 | } |
| 6427 | |
| 6428 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6429 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 6430 | * return {@link #STATE_USER_UNMANAGED} |
| 6431 | * @hide |
| 6432 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 6433 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6434 | @UserProvisioningState |
| 6435 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6436 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6437 | if (mService != null) { |
| 6438 | try { |
| 6439 | return mService.getUserProvisioningState(); |
| 6440 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6441 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6442 | } |
| 6443 | } |
| 6444 | return STATE_USER_UNMANAGED; |
| 6445 | } |
| 6446 | |
| 6447 | /** |
| 6448 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 6449 | * |
| 6450 | * @param state to store |
| 6451 | * @param userHandle for user |
| 6452 | * @hide |
| 6453 | */ |
| 6454 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 6455 | if (mService != null) { |
| 6456 | try { |
| 6457 | mService.setUserProvisioningState(state, userHandle); |
| 6458 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6459 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6460 | } |
| 6461 | } |
| 6462 | } |
| 6463 | |
| 6464 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame^] | 6465 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 6466 | * 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] | 6467 | * |
| 6468 | * @param admin Which profile or device owner this request is associated with. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame^] | 6469 | * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored. |
| 6470 | * |
| 6471 | * @throws NullPointerException if {@code ids} is null or contains null elements. |
| 6472 | * @throws IllegalArgumentException if {@code ids} contains an empty string. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6473 | */ |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame^] | 6474 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6475 | throwIfParentInstance("setAffiliationIds"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6476 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame^] | 6477 | mService.setAffiliationIds(admin, ids); |
| 6478 | } catch (RemoteException e) { |
| 6479 | throw e.rethrowFromSystemServer(); |
| 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | /** |
| 6484 | * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 6485 | * empty list if none have been set. |
| 6486 | */ |
| 6487 | public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) { |
| 6488 | throwIfParentInstance("getAffiliationIds"); |
| 6489 | try { |
| 6490 | return mService.getAffiliationIds(admin); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6491 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6492 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6493 | } |
| 6494 | } |
| 6495 | |
| 6496 | /** |
| 6497 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame^] | 6498 | * Returns whether this user/profile is affiliated with the device. |
| 6499 | * <p> |
| 6500 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 6501 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 6502 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6503 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6504 | */ |
| 6505 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6506 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6507 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame^] | 6508 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6509 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6510 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6511 | } |
| 6512 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6513 | |
| 6514 | /** |
| 6515 | * @hide |
| 6516 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 6517 | * to be started |
| 6518 | * @param packageName the package to check for |
| 6519 | * @return whether the uninstall intent for {@code packageName} is pending |
| 6520 | */ |
| 6521 | public boolean isUninstallInQueue(String packageName) { |
| 6522 | try { |
| 6523 | return mService.isUninstallInQueue(packageName); |
| 6524 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6525 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | /** |
| 6530 | * @hide |
| 6531 | * @param packageName the package containing active DAs to be uninstalled |
| 6532 | */ |
| 6533 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 6534 | try { |
| 6535 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 6536 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6537 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6538 | } |
| 6539 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6540 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 6541 | /** |
| 6542 | * @hide |
| 6543 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 6544 | * If the admin is a profile owner or device owner it will still be removed. |
| 6545 | * |
| 6546 | * @param userHandle user id to remove the admin for. |
| 6547 | * @param admin The administration compononent to remove. |
| 6548 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 6549 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 6550 | */ |
| 6551 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 6552 | try { |
| 6553 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 6554 | } catch (RemoteException re) { |
| 6555 | throw re.rethrowFromSystemServer(); |
| 6556 | } |
| 6557 | } |
| 6558 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 6559 | /** |
| 6560 | * @hide |
| 6561 | * @return whether {@link android.provider.Settings.Global#DEVICE_PROVISIONED} has ever been set |
| 6562 | * to 1. |
| 6563 | */ |
| 6564 | public boolean isDeviceProvisioned() { |
| 6565 | try { |
| 6566 | return mService.isDeviceProvisioned(); |
| 6567 | } catch (RemoteException re) { |
| 6568 | throw re.rethrowFromSystemServer(); |
| 6569 | } |
| 6570 | } |
| 6571 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 6572 | /** |
| 6573 | * @hide |
| 6574 | * Writes that the provisioning configuration has been applied. |
| 6575 | */ |
| 6576 | public void setDeviceProvisioningConfigApplied() { |
| 6577 | try { |
| 6578 | mService.setDeviceProvisioningConfigApplied(); |
| 6579 | } catch (RemoteException re) { |
| 6580 | throw re.rethrowFromSystemServer(); |
| 6581 | } |
| 6582 | } |
| 6583 | |
| 6584 | /** |
| 6585 | * @hide |
| 6586 | * @return whether the provisioning configuration has been applied. |
| 6587 | */ |
| 6588 | public boolean isDeviceProvisioningConfigApplied() { |
| 6589 | try { |
| 6590 | return mService.isDeviceProvisioningConfigApplied(); |
| 6591 | } catch (RemoteException re) { |
| 6592 | throw re.rethrowFromSystemServer(); |
| 6593 | } |
| 6594 | } |
| 6595 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 6596 | /** |
| 6597 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 6598 | * Force update user setup completed status. This API has no effect on user build. |
| 6599 | * @throws {@link SecurityException} if the caller has no |
| 6600 | * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 6601 | * not {@link UserHandle.SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 6602 | */ |
| 6603 | public void forceUpdateUserSetupComplete() { |
| 6604 | try { |
| 6605 | mService.forceUpdateUserSetupComplete(); |
| 6606 | } catch (RemoteException re) { |
| 6607 | throw re.rethrowFromSystemServer(); |
| 6608 | } |
| 6609 | } |
| 6610 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6611 | private void throwIfParentInstance(String functionName) { |
| 6612 | if (mParentInstance) { |
| 6613 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 6614 | } |
| 6615 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 6616 | |
| 6617 | /** |
| 6618 | * @hide |
| 6619 | * Enable backup service. |
| 6620 | * <p>This includes all backup and restore mechanisms. |
| 6621 | * Setting this to {@code false} will make backup service no-op or return empty results. |
| 6622 | * |
| 6623 | * <p>There must be only one user on the device, managed by the device owner. |
| 6624 | * Otherwise a {@link SecurityException} will be thrown. |
| 6625 | * |
| 6626 | * <p>Backup service is off by default when device owner is present. |
| 6627 | */ |
| 6628 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 6629 | try { |
| 6630 | mService.setBackupServiceEnabled(admin, enabled); |
| 6631 | } catch (RemoteException re) { |
| 6632 | throw re.rethrowFromSystemServer(); |
| 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | /** |
| 6637 | * @hide |
| 6638 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
| 6639 | */ |
| 6640 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
| 6641 | try { |
| 6642 | return mService.isBackupServiceEnabled(admin); |
| 6643 | } catch (RemoteException re) { |
| 6644 | throw re.rethrowFromSystemServer(); |
| 6645 | } |
| 6646 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 6647 | |
| 6648 | /** |
| 6649 | * Called by a device owner to control the network logging feature. Logging can only be |
| 6650 | * enabled on single user devices where the sole user is managed by the device owner. If a new |
| 6651 | * user is added on the device, logging is disabled. |
| 6652 | * |
| 6653 | * <p> Network logs contain DNS lookup and connect() library call events. |
| 6654 | * |
| 6655 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6656 | * @param enabled whether network logging should be enabled or not. |
| 6657 | * @throws {@link SecurityException} if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6658 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 6659 | * |
| 6660 | * @hide |
| 6661 | */ |
| 6662 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 6663 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 6664 | try { |
| 6665 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 6666 | } catch (RemoteException re) { |
| 6667 | throw re.rethrowFromSystemServer(); |
| 6668 | } |
| 6669 | } |
| 6670 | |
| 6671 | /** |
| 6672 | * Return whether network logging is enabled by a device owner. |
| 6673 | * |
| 6674 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6675 | * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise. |
| 6676 | * @throws {@link SecurityException} if {@code admin} is not a device owner. |
| 6677 | * |
| 6678 | * @hide |
| 6679 | */ |
| 6680 | public boolean isNetworkLoggingEnabled(@NonNull ComponentName admin) { |
| 6681 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 6682 | try { |
| 6683 | return mService.isNetworkLoggingEnabled(admin); |
| 6684 | } catch (RemoteException re) { |
| 6685 | throw re.rethrowFromSystemServer(); |
| 6686 | } |
| 6687 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6688 | |
| 6689 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 6690 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 6691 | * A device owner has to provide a batchToken provided as part of |
| 6692 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 6693 | * 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] | 6694 | * |
| 6695 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 6696 | * |
| 6697 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 6698 | * |
| 6699 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 6700 | * after the device device owner has been notified via |
| 6701 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 6702 | * |
| 6703 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 6704 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6705 | * @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] | 6706 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 6707 | * logging is disabled. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6708 | * @throws {@link SecurityException} if {@code admin} is not a device owner. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 6709 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6710 | * |
| 6711 | * @hide |
| 6712 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 6713 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 6714 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6715 | throwIfParentInstance("retrieveNetworkLogs"); |
| 6716 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 6717 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6718 | } catch (RemoteException re) { |
| 6719 | throw re.rethrowFromSystemServer(); |
| 6720 | } |
| 6721 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 6722 | |
| 6723 | /** |
| 6724 | * Called by device owner/ profile owner in managed profile to bind the service with each other. |
| 6725 | * The service must be unexported. Note that the {@link Context} used to obtain this |
| 6726 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 6727 | * to bind to the {@link android.app.Service}. |
| 6728 | * STOPSHIP (b/31952368): Update the javadoc after we policy to control which packages can talk. |
| 6729 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6730 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 6731 | * explicit component name or a package name to match an |
| 6732 | * {@link IntentFilter} published by a service. |
| 6733 | * @param conn Receives information as the service is started and stopped. This must be a |
| 6734 | * valid {@link ServiceConnection} object; it must not be {@code null}. |
| 6735 | * @param flags Operation options for the binding operation. See |
| 6736 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
| 6737 | * @param targetUser Which user to bind to. |
| 6738 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 6739 | * {@code false} is returned if the connection is not made and you will not |
| 6740 | * receive the service object. |
| 6741 | * @see Context#bindService(Intent, ServiceConnection, int) |
| 6742 | */ |
| 6743 | public boolean bindDeviceAdminServiceAsUser( |
| 6744 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 6745 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 6746 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 6747 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 6748 | try { |
| 6749 | final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags); |
| 6750 | serviceIntent.prepareToLeaveProcess(mContext); |
| 6751 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 6752 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 6753 | sd, flags, targetUser.getIdentifier()); |
| 6754 | } catch (RemoteException re) { |
| 6755 | throw re.rethrowFromSystemServer(); |
| 6756 | } |
| 6757 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 6758 | |
| 6759 | /** |
| 6760 | * Called by the system to get the time at which the device owner last retrieved security |
| 6761 | * logging entries. |
| 6762 | * |
| 6763 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 6764 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
| 6765 | * |
| 6766 | * @hide |
| 6767 | */ |
| 6768 | public long getLastSecurityLogRetrievalTime() { |
| 6769 | try { |
| 6770 | return mService.getLastSecurityLogRetrievalTime(); |
| 6771 | } catch (RemoteException re) { |
| 6772 | throw re.rethrowFromSystemServer(); |
| 6773 | } |
| 6774 | } |
| 6775 | |
| 6776 | /** |
| 6777 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 6778 | * |
| 6779 | * @return the time at which the device owner most recently requested a bug report, in |
| 6780 | * milliseconds since epoch; -1 if a bug report was never requested. |
| 6781 | * |
| 6782 | * @hide |
| 6783 | */ |
| 6784 | public long getLastBugReportRequestTime() { |
| 6785 | try { |
| 6786 | return mService.getLastBugReportRequestTime(); |
| 6787 | } catch (RemoteException re) { |
| 6788 | throw re.rethrowFromSystemServer(); |
| 6789 | } |
| 6790 | } |
| 6791 | |
| 6792 | /** |
| 6793 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 6794 | * events. |
| 6795 | * |
| 6796 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 6797 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
| 6798 | * |
| 6799 | * @hide |
| 6800 | */ |
| 6801 | public long getLastNetworkLogRetrievalTime() { |
| 6802 | try { |
| 6803 | return mService.getLastNetworkLogRetrievalTime(); |
| 6804 | } catch (RemoteException re) { |
| 6805 | throw re.rethrowFromSystemServer(); |
| 6806 | } |
| 6807 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 6808 | } |