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 | |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 22 | import android.annotation.SdkConstant; |
| 23 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 24 | import android.annotation.SystemApi; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 25 | import android.app.Activity; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 26 | import android.content.ComponentName; |
| 27 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 28 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 29 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 30 | import android.content.pm.ActivityInfo; |
| 31 | import android.content.pm.PackageManager; |
| 32 | import android.content.pm.ResolveInfo; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 33 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 34 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 35 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 36 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 37 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 38 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 39 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 40 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 41 | import android.os.RemoteException; |
| 42 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 43 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 44 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 45 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 46 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 47 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 48 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 49 | import android.util.Log; |
| 50 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 51 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 52 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 53 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 54 | import org.xmlpull.v1.XmlPullParserException; |
| 55 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 56 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 57 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 58 | import java.lang.annotation.Retention; |
| 59 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 60 | import java.net.InetSocketAddress; |
| 61 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 62 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 63 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 64 | import java.security.PrivateKey; |
| 65 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 66 | import java.security.cert.CertificateException; |
| 67 | import java.security.cert.CertificateFactory; |
| 68 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 69 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 70 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 71 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 72 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 73 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 74 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 75 | |
| 76 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 77 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 78 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 79 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally, |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 80 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 81 | * accessible to all device administrators unless the documentation for that method specifies that |
| 82 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 83 | * |
| 84 | * <div class="special reference"> |
| 85 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 86 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 87 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 88 | * developer guide. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 89 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 90 | */ |
| 91 | public class DevicePolicyManager { |
| 92 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 93 | |
| 94 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 95 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 96 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 97 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 98 | private static final String REMOTE_EXCEPTION_MESSAGE = |
| 99 | "Failed to talk with device policy manager service"; |
| 100 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 101 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 102 | this(context, |
| 103 | IDevicePolicyManager.Stub.asInterface( |
| 104 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 105 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 108 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 109 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 110 | protected DevicePolicyManager( |
| 111 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 112 | mContext = context; |
| 113 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 114 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** @hide */ |
| 118 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 119 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 120 | return me.mService != null ? me : null; |
| 121 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 122 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 123 | /** @hide test will override it. */ |
| 124 | @VisibleForTesting |
| 125 | protected int myUserId() { |
| 126 | return UserHandle.myUserId(); |
| 127 | } |
| 128 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 129 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 130 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 131 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 132 | * <p>A managed profile allows data separation for example for the usage of a |
| 133 | * device as a personal and corporate device. The user which provisioning is started from and |
| 134 | * the managed profile share a launcher. |
| 135 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 136 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 137 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 138 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 139 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 140 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 141 | * {@link #isProvisioningAllowed(String)}. |
| 142 | * |
| 143 | * <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] | 144 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 145 | * 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] | 146 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 147 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 148 | * |
| 149 | * <p> The intent may also contain the following extras: |
| 150 | * <ul> |
| 151 | * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li> |
| 152 | * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li> |
| 153 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 154 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 155 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 156 | * in the provisioning intent. The |
| 157 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 158 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 159 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 160 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 161 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 162 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 163 | * |
| 164 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 165 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 166 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 167 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 168 | * 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] | 169 | */ |
| 170 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 171 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 172 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 173 | |
| 174 | /** |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 175 | * @hide |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 176 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 177 | * |
| 178 | * <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] | 179 | * 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] | 180 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 181 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 182 | * allowed. |
| 183 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 184 | * <p>This intent should contain the extra |
| 185 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 186 | * |
| 187 | * <p> If provisioning fails, the device returns to its previous state. |
| 188 | * |
| 189 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 190 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 191 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 192 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 193 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 194 | */ |
| 195 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 196 | public static final String ACTION_PROVISION_MANAGED_USER |
| 197 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 198 | |
| 199 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 200 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 201 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 202 | * |
| 203 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 204 | * A device owner has full control over the device. The device owner can not be modified by the |
| 205 | * user. |
| 206 | * |
| 207 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 208 | * employee or client. |
| 209 | * |
| 210 | * <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] | 211 | * It is possible to check if provisioning is allowed or not by querying the method |
| 212 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 213 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 214 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 215 | * <ul> |
| 216 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 217 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 218 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 219 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 220 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 221 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 222 | * </ul> |
| 223 | * |
| 224 | * <p> When device owner provisioning has completed, an intent of the type |
| 225 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 226 | * device owner. |
| 227 | * |
| 228 | * <p> If provisioning fails, the device is factory reset. |
| 229 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 230 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 231 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 232 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 233 | * 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] | 234 | */ |
| 235 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 236 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 237 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 238 | |
| 239 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 240 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 241 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 242 | * |
| 243 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 244 | * management state that is distinct from that reached by |
| 245 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 246 | * user, and only has control over device-wide policies, not individual users and their data. |
| 247 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 248 | * this form of device management. |
| 249 | * |
| 250 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 251 | * A device owner has full control over the device. The device owner can not be modified by the |
| 252 | * user. |
| 253 | * |
| 254 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 255 | * employee or client. |
| 256 | * |
| 257 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 258 | * It is possible to check if provisioning is allowed or not by querying the method |
| 259 | * {@link #isProvisioningAllowed(String)}. |
| 260 | * |
| 261 | * <p>The intent contains the following extras: |
| 262 | * <ul> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 267 | * </ul> |
| 268 | * |
| 269 | * <p> When device owner provisioning has completed, an intent of the type |
| 270 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 271 | * device owner. |
| 272 | * |
| 273 | * <p> If provisioning fails, the device is factory reset. |
| 274 | * |
| 275 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 276 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 277 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 278 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 279 | * |
| 280 | * @hide |
| 281 | */ |
| 282 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 283 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 284 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 285 | |
| 286 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 287 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 288 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 289 | * <ul> |
| 290 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 291 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 292 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 293 | * </ul> |
| 294 | * |
| 295 | * @hide |
| 296 | */ |
| 297 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 298 | public static final String ACTION_PROVISION_FINALIZATION |
| 299 | = "android.app.action.PROVISION_FINALIZATION"; |
| 300 | |
| 301 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 302 | * 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] | 303 | * allows a mobile device management application or NFC programmer application which starts |
| 304 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 305 | * <p> |
| 306 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 307 | * sends the intent to pass data to itself on the newly created profile. |
| 308 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 309 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 310 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 311 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 312 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 313 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 314 | * management application after provisioning. |
| 315 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 316 | * <p> |
| 317 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 318 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 319 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 320 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 321 | */ |
| 322 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 323 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 324 | |
| 325 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 326 | * A String extra holding the package name of the mobile device management application that |
| 327 | * will be set as the profile owner or device owner. |
| 328 | * |
| 329 | * <p>If an application starts provisioning directly via an intent with action |
| 330 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 331 | * application that started provisioning. The package will be set as profile owner in that case. |
| 332 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 333 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 334 | * 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] | 335 | * |
| 336 | * <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] | 337 | * This receiver will be set as the profile or device owner and active admin. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 338 | |
| 339 | * @see DeviceAdminReceiver |
| 340 | * @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] | 341 | * supported, but only if there is only one device admin receiver in the package that requires |
| 342 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 343 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 344 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 345 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 346 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 347 | |
| 348 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 349 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 350 | * application that will be set as the profile owner or device owner and active admin. |
| 351 | * |
| 352 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 353 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 354 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 355 | * 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] | 356 | * |
| 357 | * <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] | 358 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 359 | * message containing an NFC record with MIME type |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 360 | * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be |
Rubin Xu | 44ef750b | 2015-03-23 16:51:33 +0000 | [diff] [blame] | 361 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 362 | * |
| 363 | * @see DeviceAdminReceiver |
| 364 | */ |
| 365 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 366 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 367 | |
| 368 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 369 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 370 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 371 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 372 | * |
| 373 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 374 | */ |
| 375 | |
| 376 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 377 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 378 | |
| 379 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 380 | * A String extra that, holds the email address of the account which a managed profile is |
| 381 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 382 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 383 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 384 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 385 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 386 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 387 | * contains this extra, it is forwarded in the |
| 388 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 389 | * device management application that was set as the profile owner during provisioning. |
| 390 | * 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] | 391 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 392 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 393 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 394 | |
| 395 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 396 | * A integer extra indicating the predominant color to show during the provisioning. |
| 397 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 398 | * |
| 399 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 400 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 401 | */ |
| 402 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 403 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 404 | |
| 405 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 406 | * 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] | 407 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 408 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 409 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 410 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 411 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 412 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 413 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 414 | |
| 415 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 416 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 417 | * will be set to. |
| 418 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 419 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 420 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 421 | */ |
| 422 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 423 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 424 | |
| 425 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 426 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 427 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 428 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 429 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 430 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 431 | */ |
| 432 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 433 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 434 | |
| 435 | /** |
| 436 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 437 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 438 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 439 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 440 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 441 | */ |
| 442 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 443 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 444 | |
| 445 | /** |
| 446 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 447 | * owner provisioning for downloading the mobile device management application. |
| 448 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 449 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 450 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 451 | */ |
| 452 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 453 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 454 | |
| 455 | /** |
| 456 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 457 | * is hidden or not. |
| 458 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 459 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 460 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 461 | */ |
| 462 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 463 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 464 | |
| 465 | /** |
| 466 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 467 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 468 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 469 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 470 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 471 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 472 | */ |
| 473 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 474 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 475 | |
| 476 | /** |
| 477 | * A String extra holding the password of the wifi network in |
| 478 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 479 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 480 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 481 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 482 | */ |
| 483 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 484 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 485 | |
| 486 | /** |
| 487 | * A String extra holding the proxy host for the wifi network in |
| 488 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 489 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 490 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 491 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 492 | */ |
| 493 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 494 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 495 | |
| 496 | /** |
| 497 | * An int extra holding the proxy port for the wifi network in |
| 498 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 499 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 500 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 501 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 502 | */ |
| 503 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 504 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 505 | |
| 506 | /** |
| 507 | * A String extra holding the proxy bypass for the wifi network in |
| 508 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 509 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 510 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 511 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 512 | */ |
| 513 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 514 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 515 | |
| 516 | /** |
| 517 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 518 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 519 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 520 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 521 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 522 | */ |
| 523 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 524 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 525 | |
| 526 | /** |
| 527 | * A String extra holding a url that specifies the download location of the device admin |
| 528 | * package. When not provided it is assumed that the device admin package is already installed. |
| 529 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 530 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 531 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 532 | */ |
| 533 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 534 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 535 | |
| 536 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 537 | * An int extra holding a minimum required version code for the device admin package. If the |
| 538 | * device admin is already installed on the device, it will only be re-downloaded from |
| 539 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 540 | * installed package is less than this version code. |
| 541 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 542 | * <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] | 543 | * provisioning via an NFC bump. |
| 544 | */ |
| 545 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 546 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 547 | |
| 548 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 549 | * A String extra holding a http cookie header which should be used in the http request to the |
| 550 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 551 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 552 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 553 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 554 | */ |
| 555 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 556 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 557 | |
| 558 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 559 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 560 | * the file at download location specified in |
| 561 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 562 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 563 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 564 | * present. The provided checksum should match the checksum of the file at the download |
| 565 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 566 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 567 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 568 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 569 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 570 | * |
| 571 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 572 | * 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] | 573 | * 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] | 574 | * 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] | 575 | */ |
| 576 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 577 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 578 | |
| 579 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 580 | * 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] | 581 | * android package archive at the download location specified in {@link |
| 582 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 583 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 584 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 585 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 586 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 587 | * |
| 588 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 589 | * present. The provided checksum should match the checksum of any signature of the file at |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 590 | * the download location. If the checksum does not match an error will be shown to the user and |
| 591 | * the user will be asked to factory reset the device. |
| 592 | * |
| 593 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 594 | * provisioning via an NFC bump. |
| 595 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 596 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 597 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 598 | |
| 599 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 600 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 601 | * has completed successfully. |
| 602 | * |
| 603 | * <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] | 604 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 605 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 606 | * <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] | 607 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 608 | */ |
| 609 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 610 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 611 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 612 | |
| 613 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 614 | * A boolean extra indicating whether device encryption can be skipped as part of Device Owner |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 615 | * provisioning. |
| 616 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 617 | * <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] | 618 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 619 | */ |
| 620 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 621 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 622 | |
| 623 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 624 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 625 | * provisioning. If this extra is not passed, a default image will be shown. |
| 626 | * <h5>The following URI schemes are accepted:</h5> |
| 627 | * <ul> |
| 628 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 629 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 630 | * </ul> |
| 631 | * |
| 632 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 633 | * pixed density for the device. |
| 634 | * |
| 635 | * <p> If a content: URI is passed, the intent should have the flag |
| 636 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 637 | * {@link android.content.ClipData} of the intent too. |
| 638 | * |
| 639 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 640 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 641 | */ |
| 642 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 643 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 644 | |
| 645 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 646 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 647 | * during setup-wizard. |
| 648 | * |
| 649 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 650 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 651 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 652 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 653 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 654 | * |
| 655 | * @hide |
| 656 | */ |
| 657 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 658 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 659 | |
| 660 | /** |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 661 | * This MIME type is used for starting the Device Owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 662 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 663 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 664 | * A device owner has full control over the device. The device owner can not be modified by the |
| 665 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 666 | * reset. |
| 667 | * |
| 668 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 669 | * employee or client. |
| 670 | * |
| 671 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 672 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 673 | * <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] | 674 | * contains the following properties: |
| 675 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 676 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 677 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 678 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 679 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 680 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 681 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 682 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 683 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 684 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 685 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 686 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 687 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 688 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 689 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 690 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 691 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 692 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 693 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 694 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 695 | * 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] | 696 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 697 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 698 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 699 | */ |
| 700 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 701 | = "application/com.android.managedprovisioning"; |
| 702 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 703 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 704 | * Activity action: ask the user to add a new device administrator to the system. |
| 705 | * The desired policy is the ComponentName of the policy in the |
| 706 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 707 | * bring the user through adding the device administrator to the system (or |
| 708 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 709 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 710 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 711 | * field to provide the user with additional explanation (in addition |
| 712 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 713 | * |
| 714 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 715 | * user intervention). However, if your administrator has been updated and is requesting |
| 716 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 717 | * 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] | 718 | */ |
| 719 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 720 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 721 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 722 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 723 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 724 | * @hide |
| 725 | * 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] | 726 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 727 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 728 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 729 | * 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] | 730 | * to remotely control restrictions on the user. |
| 731 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 732 | * <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] | 733 | * result of whether or not the user approved the action. If approved, the result will |
| 734 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 735 | * as a profile owner. |
| 736 | * |
| 737 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 738 | * field to provide the user with additional explanation (in addition |
| 739 | * to your component's description) about what is being added. |
| 740 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 741 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 742 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 743 | */ |
| 744 | @SystemApi |
| 745 | public static final String ACTION_SET_PROFILE_OWNER |
| 746 | = "android.app.action.SET_PROFILE_OWNER"; |
| 747 | |
| 748 | /** |
| 749 | * @hide |
| 750 | * Name of the profile owner admin that controls the user. |
| 751 | */ |
| 752 | @SystemApi |
| 753 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 754 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 755 | |
| 756 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 757 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 758 | * 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] | 759 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 760 | * @hide |
| 761 | */ |
| 762 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 763 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 764 | |
| 765 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 766 | * Broadcast action: sent when the device owner is set or changed. |
| 767 | * |
| 768 | * This broadcast is sent only to the primary user. |
| 769 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 770 | */ |
| 771 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 772 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 773 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 774 | |
| 775 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 776 | * The ComponentName of the administrator component. |
| 777 | * |
| 778 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 779 | */ |
| 780 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 781 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 782 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 783 | * An optional CharSequence providing additional explanation for why the |
| 784 | * admin is being added. |
| 785 | * |
| 786 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 787 | */ |
| 788 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 789 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 790 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 791 | * Activity action: have the user enter a new password. This activity should |
| 792 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 793 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 794 | * enter a new password that meets the current requirements. You can use |
| 795 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 796 | * have the user select a new password in order to meet the current |
| 797 | * constraints. Upon being resumed from this activity, you can check the new |
| 798 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 799 | * |
| 800 | * If the intent is launched from within a managed profile with a profile |
| 801 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 802 | * this will trigger entering a new password for the parent of the profile. |
| 803 | * For all other cases it will trigger entering a new password for the user |
| 804 | * or profile it is launched from. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 805 | */ |
| 806 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 807 | public static final String ACTION_SET_NEW_PASSWORD |
| 808 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 809 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 810 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 811 | * Activity action: have the user enter a new password for the parent profile. |
| 812 | * If the intent is launched from within a managed profile, this will trigger |
| 813 | * entering a new password for the parent of the profile. In all other cases |
| 814 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 815 | */ |
| 816 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 817 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 818 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 819 | |
| 820 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 821 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 822 | * the parent profile to access intents sent from the managed profile. |
| 823 | * That is, when an app in the managed profile calls |
| 824 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 825 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 826 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 827 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 828 | |
| 829 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 830 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 831 | * the managed profile to access intents sent from the parent profile. |
| 832 | * That is, when an app in the parent profile calls |
| 833 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 834 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 835 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 836 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 837 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 838 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 839 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 840 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 841 | */ |
| 842 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 843 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 844 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 845 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 846 | /** |
| 847 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 848 | * Already granted or denied permissions are not affected by this. |
| 849 | */ |
| 850 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 851 | |
| 852 | /** |
| 853 | * Permission policy to always grant new permission requests for runtime permissions. |
| 854 | * Already granted or denied permissions are not affected by this. |
| 855 | */ |
| 856 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 857 | |
| 858 | /** |
| 859 | * Permission policy to always deny new permission requests for runtime permissions. |
| 860 | * Already granted or denied permissions are not affected by this. |
| 861 | */ |
| 862 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 863 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 864 | /** |
| 865 | * Runtime permission state: The user can manage the permission |
| 866 | * through the UI. |
| 867 | */ |
| 868 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 869 | |
| 870 | /** |
| 871 | * Runtime permission state: The permission is granted to the app |
| 872 | * and the user cannot manage the permission through the UI. |
| 873 | */ |
| 874 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 875 | |
| 876 | /** |
| 877 | * Runtime permission state: The permission is denied to the app |
| 878 | * and the user cannot manage the permission through the UI. |
| 879 | */ |
| 880 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 881 | |
| 882 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 883 | * No management for current user in-effect. This is the default. |
| 884 | * @hide |
| 885 | */ |
| 886 | public static final int STATE_USER_UNMANAGED = 0; |
| 887 | |
| 888 | /** |
| 889 | * Management partially setup, user setup needs to be completed. |
| 890 | * @hide |
| 891 | */ |
| 892 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 893 | |
| 894 | /** |
| 895 | * Management partially setup, user setup completed. |
| 896 | * @hide |
| 897 | */ |
| 898 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 899 | |
| 900 | /** |
| 901 | * Management setup and active on current user. |
| 902 | * @hide |
| 903 | */ |
| 904 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 905 | |
| 906 | /** |
| 907 | * Management partially setup on a managed profile. |
| 908 | * @hide |
| 909 | */ |
| 910 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 911 | |
| 912 | /** |
| 913 | * @hide |
| 914 | */ |
| 915 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 916 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 917 | @Retention(RetentionPolicy.SOURCE) |
| 918 | public @interface UserProvisioningState {} |
| 919 | |
| 920 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 921 | * Return true if the given administrator component is currently |
| 922 | * active (enabled) in the system. |
| 923 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 924 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 925 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /** |
| 929 | * @see #isAdminActive(ComponentName) |
| 930 | * @hide |
| 931 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 932 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 933 | if (mService != null) { |
| 934 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 935 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 936 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 937 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | return false; |
| 941 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 942 | /** |
| 943 | * Return true if the given administrator component is currently being removed |
| 944 | * for the user. |
| 945 | * @hide |
| 946 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 947 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 948 | if (mService != null) { |
| 949 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 950 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 951 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 952 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | return false; |
| 956 | } |
| 957 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 958 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 959 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 960 | * Return a list of all currently active device administrators' component |
| 961 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 962 | * returned. |
| 963 | */ |
| 964 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 965 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /** |
| 969 | * @see #getActiveAdmins() |
| 970 | * @hide |
| 971 | */ |
| 972 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 973 | if (mService != null) { |
| 974 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 975 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 976 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 977 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | return null; |
| 981 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 982 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 983 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 984 | * Used by package administration code to determine if a package can be stopped |
| 985 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 986 | * @hide |
| 987 | */ |
| 988 | public boolean packageHasActiveAdmins(String packageName) { |
| 989 | if (mService != null) { |
| 990 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 991 | return mService.packageHasActiveAdmins(packageName, myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 992 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 993 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | return false; |
| 997 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 998 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 999 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1000 | * Remove a current administration component. This can only be called |
| 1001 | * by the application that owns the administration component; if you |
| 1002 | * try to remove someone else's component, a security exception will be |
| 1003 | * thrown. |
| 1004 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1005 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1006 | if (mService != null) { |
| 1007 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1008 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1009 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1010 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1014 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1015 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1016 | * Returns true if an administrator has been granted a particular device policy. This can |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1017 | * be used to check whether the administrator was activated under an earlier set of policies, |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1018 | * but requires additional policies after an upgrade. |
| 1019 | * |
| 1020 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 1021 | * an active administrator, or an exception will be thrown. |
| 1022 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 1023 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1024 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1025 | if (mService != null) { |
| 1026 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1027 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1028 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1029 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1036 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1037 | * |
| 1038 | * @hide |
| 1039 | */ |
| 1040 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1041 | if (mService != null) { |
| 1042 | try { |
| 1043 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1044 | } catch (RemoteException e) { |
| 1045 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1046 | } |
| 1047 | } |
| 1048 | return false; |
| 1049 | } |
| 1050 | |
| 1051 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1052 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1053 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1054 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1055 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1056 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1057 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1058 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1059 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1060 | * recognition technology. This implies technologies that can recognize the identity of |
| 1061 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1062 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1063 | */ |
| 1064 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1065 | |
| 1066 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1067 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1068 | * 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] | 1069 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1070 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1071 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1072 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1073 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1074 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1075 | * password containing at least numeric characters. Note that quality |
| 1076 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1077 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1078 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1079 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1080 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1081 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1082 | * password containing at least numeric characters with no repeating (4444) |
| 1083 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1084 | * constants are ordered so that higher values are more restrictive. |
| 1085 | */ |
| 1086 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1087 | |
| 1088 | /** |
| 1089 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1090 | * password containing at least alphabetic (or other symbol) characters. |
| 1091 | * Note that quality constants are ordered so that higher values are more |
| 1092 | * restrictive. |
| 1093 | */ |
| 1094 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1095 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1096 | /** |
| 1097 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1098 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1099 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1100 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1101 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1102 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1103 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1104 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1105 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1106 | * password containing at least a letter, a numerical digit and a special |
| 1107 | * symbol, by default. With this password quality, passwords can be |
| 1108 | * restricted to contain various sets of characters, like at least an |
| 1109 | * uppercase letter, etc. These are specified using various methods, |
| 1110 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1111 | * that quality constants are ordered so that higher values are more |
| 1112 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1113 | */ |
| 1114 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1115 | |
| 1116 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1117 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1118 | * modify password. In case this password quality is set, the password is |
| 1119 | * managed by a profile owner. The profile owner can set any password, |
| 1120 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1121 | * that quality constants are ordered so that higher values are more |
| 1122 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1123 | * the highest. |
| 1124 | * @hide |
| 1125 | */ |
| 1126 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1127 | |
| 1128 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1129 | * Called by an application that is administering the device to set the |
| 1130 | * password restrictions it is imposing. After setting this, the user |
| 1131 | * will not be able to enter a new password that is not at least as |
| 1132 | * restrictive as what has been set. Note that the current password |
| 1133 | * will remain until the user has set a new one, so the change does not |
| 1134 | * take place immediately. To prompt the user for a new password, use |
| 1135 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1136 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1137 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 1138 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1139 | * the user's preference, and any other considerations) is the one that |
| 1140 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1141 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1142 | * <p>The calling device admin must have requested |
| 1143 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1144 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1145 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1147 | * @param quality The new desired quality. One of |
| 1148 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1149 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1150 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1151 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1152 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1153 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1154 | if (mService != null) { |
| 1155 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1156 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1157 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1158 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1162 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1163 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1164 | * Retrieve the current minimum password quality for all admins of this user |
| 1165 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1166 | * @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] | 1167 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1168 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1169 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1170 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1174 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1175 | if (mService != null) { |
| 1176 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1177 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1178 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1179 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1180 | } |
| 1181 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1182 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1183 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1184 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1185 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1186 | * Called by an application that is administering the device to set the |
| 1187 | * minimum allowed password length. After setting this, the user |
| 1188 | * will not be able to enter a new password that is not at least as |
| 1189 | * restrictive as what has been set. Note that the current password |
| 1190 | * will remain until the user has set a new one, so the change does not |
| 1191 | * take place immediately. To prompt the user for a new password, use |
| 1192 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1193 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1194 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1195 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1196 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1197 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1198 | * <p>The calling device admin must have requested |
| 1199 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1200 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1201 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1202 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1203 | * @param length The new desired minimum password length. A value of 0 |
| 1204 | * means there is no restriction. |
| 1205 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1206 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1207 | if (mService != null) { |
| 1208 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1209 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1210 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1211 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1215 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1216 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1217 | * Retrieve the current minimum password length for all admins of this |
| 1218 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1219 | * @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] | 1220 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1221 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1222 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1223 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1227 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1228 | if (mService != null) { |
| 1229 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1230 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1231 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1232 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | return 0; |
| 1236 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1237 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1238 | /** |
| 1239 | * Called by an application that is administering the device to set the |
| 1240 | * minimum number of upper case letters required in the password. After |
| 1241 | * setting this, the user will not be able to enter a new password that is |
| 1242 | * not at least as restrictive as what has been set. Note that the current |
| 1243 | * password will remain until the user has set a new one, so the change does |
| 1244 | * not take place immediately. To prompt the user for a new password, use |
| 1245 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1246 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1247 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1248 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1249 | * <p> |
| 1250 | * The calling device admin must have requested |
| 1251 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1252 | * this method; if it has not, a security exception will be thrown. |
| 1253 | * |
| 1254 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1255 | * with. |
| 1256 | * @param length The new desired minimum number of upper case letters |
| 1257 | * required in the password. A value of 0 means there is no |
| 1258 | * restriction. |
| 1259 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1260 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1261 | if (mService != null) { |
| 1262 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1263 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1264 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1265 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | /** |
| 1271 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1272 | * password for all admins of this user and its profiles or a particular one. |
| 1273 | * This is the same value as set by |
| 1274 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1275 | * and only applies when the password quality is |
| 1276 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1277 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1278 | * @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] | 1279 | * aggregate all admins. |
| 1280 | * @return The minimum number of upper case letters required in the |
| 1281 | * password. |
| 1282 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1283 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1284 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1288 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1289 | if (mService != null) { |
| 1290 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1291 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1292 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1293 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * Called by an application that is administering the device to set the |
| 1301 | * minimum number of lower case letters required in the password. After |
| 1302 | * setting this, the user will not be able to enter a new password that is |
| 1303 | * not at least as restrictive as what has been set. Note that the current |
| 1304 | * password will remain until the user has set a new one, so the change does |
| 1305 | * not take place immediately. To prompt the user for a new password, use |
| 1306 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1307 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1308 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1309 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1310 | * <p> |
| 1311 | * The calling device admin must have requested |
| 1312 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1313 | * this method; if it has not, a security exception will be thrown. |
| 1314 | * |
| 1315 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1316 | * with. |
| 1317 | * @param length The new desired minimum number of lower case letters |
| 1318 | * required in the password. A value of 0 means there is no |
| 1319 | * restriction. |
| 1320 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1321 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1322 | if (mService != null) { |
| 1323 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1324 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1325 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1326 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1333 | * password for all admins of this user and its profiles or a particular one. |
| 1334 | * This is the same value as set by |
| 1335 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1336 | * and only applies when the password quality is |
| 1337 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1338 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1339 | * @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] | 1340 | * aggregate all admins. |
| 1341 | * @return The minimum number of lower case letters required in the |
| 1342 | * password. |
| 1343 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1344 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1345 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1349 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1350 | if (mService != null) { |
| 1351 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1352 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1353 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1354 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | /** |
| 1361 | * Called by an application that is administering the device to set the |
| 1362 | * minimum number of letters required in the password. After setting this, |
| 1363 | * the user will not be able to enter a new password that is not at least as |
| 1364 | * restrictive as what has been set. Note that the current password will |
| 1365 | * remain until the user has set a new one, so the change does not take |
| 1366 | * place immediately. To prompt the user for a new password, use |
| 1367 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1368 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1369 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1370 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1371 | * <p> |
| 1372 | * The calling device admin must have requested |
| 1373 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1374 | * this method; if it has not, a security exception will be thrown. |
| 1375 | * |
| 1376 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1377 | * with. |
| 1378 | * @param length The new desired minimum number of letters required in the |
| 1379 | * password. A value of 0 means there is no restriction. |
| 1380 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1381 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1382 | if (mService != null) { |
| 1383 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1384 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1385 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1386 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1393 | * admins or a particular one. This is the same value as |
| 1394 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 1395 | * and only applies when the password quality is |
| 1396 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1397 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1398 | * @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] | 1399 | * aggregate all admins. |
| 1400 | * @return The minimum number of letters required in the password. |
| 1401 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1402 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1403 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1407 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1408 | if (mService != null) { |
| 1409 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1410 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1411 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1412 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
| 1418 | /** |
| 1419 | * Called by an application that is administering the device to set the |
| 1420 | * minimum number of numerical digits required in the password. After |
| 1421 | * setting this, the user will not be able to enter a new password that is |
| 1422 | * not at least as restrictive as what has been set. Note that the current |
| 1423 | * password will remain until the user has set a new one, so the change does |
| 1424 | * not take place immediately. To prompt the user for a new password, use |
| 1425 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1426 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1427 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1428 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1429 | * <p> |
| 1430 | * The calling device admin must have requested |
| 1431 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1432 | * this method; if it has not, a security exception will be thrown. |
| 1433 | * |
| 1434 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1435 | * with. |
| 1436 | * @param length The new desired minimum number of numerical digits required |
| 1437 | * in the password. A value of 0 means there is no restriction. |
| 1438 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1439 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1440 | if (mService != null) { |
| 1441 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1442 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1443 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1444 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | /** |
| 1450 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1451 | * for all admins of this user and its profiles or a particular one. |
| 1452 | * This is the same value as set by |
| 1453 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1454 | * and only applies when the password quality is |
| 1455 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1456 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1457 | * @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] | 1458 | * aggregate all admins. |
| 1459 | * @return The minimum number of numerical digits required in the password. |
| 1460 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1461 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1462 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1466 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1467 | if (mService != null) { |
| 1468 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1469 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1470 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1471 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | return 0; |
| 1475 | } |
| 1476 | |
| 1477 | /** |
| 1478 | * Called by an application that is administering the device to set the |
| 1479 | * minimum number of symbols required in the password. After setting this, |
| 1480 | * the user will not be able to enter a new password that is not at least as |
| 1481 | * restrictive as what has been set. Note that the current password will |
| 1482 | * remain until the user has set a new one, so the change does not take |
| 1483 | * place immediately. To prompt the user for a new password, use |
| 1484 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1485 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1486 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1487 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1488 | * <p> |
| 1489 | * The calling device admin must have requested |
| 1490 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1491 | * this method; if it has not, a security exception will be thrown. |
| 1492 | * |
| 1493 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1494 | * with. |
| 1495 | * @param length The new desired minimum number of symbols required in the |
| 1496 | * password. A value of 0 means there is no restriction. |
| 1497 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1498 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
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 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1502 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1503 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | /** |
| 1509 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1510 | * admins or a particular one. This is the same value as |
| 1511 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1512 | * and only applies when the password quality is |
| 1513 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1514 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1515 | * @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] | 1516 | * aggregate all admins. |
| 1517 | * @return The minimum number of symbols required in the password. |
| 1518 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1519 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1520 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1524 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1525 | if (mService != null) { |
| 1526 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1527 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1528 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1529 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | return 0; |
| 1533 | } |
| 1534 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1535 | /** |
| 1536 | * Called by an application that is administering the device to set the |
| 1537 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1538 | * required in the password. After setting this, the user will not be able |
| 1539 | * to enter a new password that is not at least as restrictive as what has |
| 1540 | * been set. Note that the current password will remain until the user has |
| 1541 | * set a new one, so the change does not take place immediately. To prompt |
| 1542 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1543 | * setting this value. This constraint is only imposed if the administrator |
| 1544 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1545 | * {@link #setPasswordQuality}. The default value is 0. |
| 1546 | * <p> |
| 1547 | * The calling device admin must have requested |
| 1548 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1549 | * this method; if it has not, a security exception will be thrown. |
| 1550 | * |
| 1551 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1552 | * with. |
| 1553 | * @param length The new desired minimum number of letters required in the |
| 1554 | * password. A value of 0 means there is no restriction. |
| 1555 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1556 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1557 | if (mService != null) { |
| 1558 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1559 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1560 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1561 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | /** |
| 1567 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1568 | * password for all admins of this user and its profiles or a particular one. |
| 1569 | * This is the same value as set by |
| 1570 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1571 | * and only applies when the password quality is |
| 1572 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1573 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1574 | * @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] | 1575 | * aggregate all admins. |
| 1576 | * @return The minimum number of letters required in the password. |
| 1577 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1578 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1579 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1583 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1584 | if (mService != null) { |
| 1585 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1586 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1587 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1588 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1594 | /** |
| 1595 | * Called by an application that is administering the device to set the length |
| 1596 | * of the password history. After setting this, the user will not be able to |
| 1597 | * enter a new password that is the same as any password in the history. Note |
| 1598 | * that the current password will remain until the user has set a new one, so |
| 1599 | * the change does not take place immediately. To prompt the user for a new |
| 1600 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1601 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1602 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1603 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1604 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1605 | * |
| 1606 | * <p> |
| 1607 | * The calling device admin must have requested |
| 1608 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1609 | * method; if it has not, a security exception will be thrown. |
| 1610 | * |
| 1611 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1612 | * with. |
| 1613 | * @param length The new desired length of password history. A value of 0 |
| 1614 | * means there is no restriction. |
| 1615 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1616 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1617 | if (mService != null) { |
| 1618 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1619 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1620 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1621 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1627 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1628 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1629 | * the device password (for all admins). |
| 1630 | * |
| 1631 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1632 | * For example, to have the password expire 5 days from now, timeout would be |
| 1633 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1634 | * |
| 1635 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1636 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1637 | * <p>The calling device admin must have requested |
| 1638 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1639 | * method; if it has not, a security exception will be thrown. |
| 1640 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1641 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1642 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1643 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1644 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1645 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1646 | * means there is no restriction (unlimited). |
| 1647 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1648 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1649 | if (mService != null) { |
| 1650 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1651 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1652 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1653 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1659 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1660 | * recurring expiration timeout provided in the call to |
| 1661 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1662 | * aggregate of all policy administrators if {@code admin} is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1663 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1664 | * @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] | 1665 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1666 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1667 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1668 | if (mService != null) { |
| 1669 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1670 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1671 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1672 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1673 | } |
| 1674 | } |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * Get the current password expiration time for the given admin or an aggregate of |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1680 | * all admins of this user and its profiles if admin is null. If the password is |
| 1681 | * expired, this will return the time since the password expired as a negative number. |
| 1682 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1683 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1684 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1685 | * @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] | 1686 | * @return The password expiration time, in ms. |
| 1687 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1688 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1689 | if (mService != null) { |
| 1690 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1691 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1692 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1693 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | return 0; |
| 1697 | } |
| 1698 | |
| 1699 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1700 | * Retrieve the current password history length for all admins of this |
| 1701 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1702 | * @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] | 1703 | * all admins. |
| 1704 | * @return The length of the password history |
| 1705 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1706 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1707 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1711 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1712 | if (mService != null) { |
| 1713 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1714 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1715 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1716 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | return 0; |
| 1720 | } |
| 1721 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1722 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1723 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1724 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1725 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1726 | * @return Returns the maximum length that the user can enter. |
| 1727 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1728 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1729 | // Kind-of arbitrary. |
| 1730 | return 16; |
| 1731 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1732 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1733 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1734 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1735 | * to meet the policy requirements (quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1736 | * requested by the admins of this user and its profiles that don't have a separate challenge. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1737 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1738 | * <p>The calling device admin must have requested |
| 1739 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1740 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1741 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1742 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1743 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1744 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1745 | if (mService != null) { |
| 1746 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1747 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1748 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1749 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1750 | } |
| 1751 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1752 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1753 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1754 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1755 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1756 | * Determine whether the current profile password the user has set is sufficient |
| 1757 | * to meet the policy requirements (quality, minimum length) that have been |
| 1758 | * requested by the admins of the parent user and its profiles. |
| 1759 | * |
| 1760 | * @param userHandle the userId of the profile to check the password for. |
| 1761 | * @return Returns true if the password would meet the current requirements, else false. |
| 1762 | * @hide |
| 1763 | */ |
| 1764 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 1765 | if (mService != null) { |
| 1766 | try { |
| 1767 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 1768 | } catch (RemoteException e) { |
| 1769 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1770 | } |
| 1771 | } |
| 1772 | return false; |
| 1773 | } |
| 1774 | |
| 1775 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1776 | * Retrieve the number of times the user has failed at entering a |
| 1777 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1778 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1779 | * <p>The calling device admin must have requested |
| 1780 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1781 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1782 | */ |
| 1783 | public int getCurrentFailedPasswordAttempts() { |
| 1784 | if (mService != null) { |
| 1785 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1786 | return mService.getCurrentFailedPasswordAttempts(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1787 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1788 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | return -1; |
| 1792 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1793 | |
| 1794 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1795 | * 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] | 1796 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1797 | * @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] | 1798 | * @hide |
| 1799 | */ |
| 1800 | public boolean getDoNotAskCredentialsOnBoot() { |
| 1801 | if (mService != null) { |
| 1802 | try { |
| 1803 | return mService.getDoNotAskCredentialsOnBoot(); |
| 1804 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1805 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1806 | } |
| 1807 | } |
| 1808 | return false; |
| 1809 | } |
| 1810 | |
| 1811 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1812 | * Setting this to a value greater than zero enables a built-in policy |
| 1813 | * that will perform a device wipe after too many incorrect |
| 1814 | * device-unlock passwords have been entered. This built-in policy combines |
| 1815 | * watching for failed passwords and wiping the device, and requires |
| 1816 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1817 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1818 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1819 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1820 | * application only, erasing or revoking credentials, or reporting the |
| 1821 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1822 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1823 | * instead. Do not use this API, because if the maximum count is reached, |
| 1824 | * the device will be wiped immediately, and your callback will not be invoked. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1825 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1826 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1827 | * @param num The number of failed password attempts at which point the |
| 1828 | * device will wipe its data. |
| 1829 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1830 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1831 | if (mService != null) { |
| 1832 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1833 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1834 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1835 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1839 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1840 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1841 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1842 | * before the device wipes itself, for all admins of this user and its profiles |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1843 | * or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1844 | * @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] | 1845 | * all admins. |
| 1846 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1847 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1848 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1852 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1853 | if (mService != null) { |
| 1854 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1855 | return mService.getMaximumFailedPasswordsForWipe( |
| 1856 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1857 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1858 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | return 0; |
| 1862 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1863 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1864 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1865 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1866 | * for the given user. So for primary user, it might return the primary or |
| 1867 | * a managed profile. For a secondary user, it would be the same as the |
| 1868 | * user passed in. |
| 1869 | * @hide Used only by Keyguard |
| 1870 | */ |
| 1871 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1872 | if (mService != null) { |
| 1873 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1874 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 1875 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1876 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1877 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | return UserHandle.USER_NULL; |
| 1881 | } |
| 1882 | |
| 1883 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1884 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1885 | * the password again until the user has entered it. |
| 1886 | */ |
| 1887 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1888 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1889 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1890 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 1891 | * If the flag is set, the device can be booted without asking for user password. |
| 1892 | * The absence of this flag does not change the current boot requirements. This flag |
| 1893 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 1894 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 1895 | * device to factory defaults. |
| 1896 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1897 | 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] | 1898 | |
| 1899 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1900 | * Force a new device unlock password (the password needed to access the |
| 1901 | * entire device, not for individual accounts) on the user. This takes |
| 1902 | * effect immediately. |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 1903 | * |
| 1904 | * <p>Calling this from a managed profile that shares the password with the owner profile |
| 1905 | * will throw a security exception. |
| 1906 | * |
| 1907 | * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
| 1908 | * device admins that are not device owner and not profile owner. |
| 1909 | * The password can now only be changed if there is currently no password set. Device owner |
| 1910 | * and profile owner can still do this.</em> |
| 1911 | * |
| 1912 | * <p>The given password must be sufficient for the |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1913 | * current password quality and length constraints as returned by |
| 1914 | * {@link #getPasswordQuality(ComponentName)} and |
| 1915 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1916 | * these constraints, then it will be rejected and false returned. Note |
| 1917 | * that the password may be a stronger quality (containing alphanumeric |
| 1918 | * characters when the requested quality is only numeric), in which case |
| 1919 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1920 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1921 | * <p>Calling with a null or empty password will clear any existing PIN, |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 1922 | * pattern or password if the current password constraints allow it. <em>Note: This will not |
| 1923 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 1924 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 1925 | * empty, except by device owner or profile owner.</em> |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1926 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1927 | * <p>The calling device admin must have requested |
| 1928 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1929 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1930 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1931 | * @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] | 1932 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1933 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1934 | * @return Returns true if the password was applied, or false if it is |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 1935 | * not acceptable for the current constraints or if the user has not been decrypted yet. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1936 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1937 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1938 | if (mParentInstance) { |
| 1939 | throw new SecurityException("Reset password does not work across profiles."); |
| 1940 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1941 | if (mService != null) { |
| 1942 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1943 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1944 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1945 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1946 | } |
| 1947 | } |
| 1948 | return false; |
| 1949 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1950 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1951 | /** |
| 1952 | * Called by an application that is administering the device to set the |
| 1953 | * maximum time for user activity until the device will lock. This limits |
| 1954 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1955 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1956 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1957 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1958 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1959 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1960 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1961 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1962 | * A value of 0 means there is no restriction. |
| 1963 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1964 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1965 | if (mService != null) { |
| 1966 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1967 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1968 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1969 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1970 | } |
| 1971 | } |
| 1972 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1973 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1974 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1975 | * Retrieve the current maximum time to unlock for all admins of this user |
| 1976 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1977 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1978 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 1979 | * @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] | 1980 | * 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] | 1981 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1982 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1983 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1987 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1988 | if (mService != null) { |
| 1989 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1990 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1991 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1992 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | return 0; |
| 1996 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1997 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1998 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1999 | * Make the device lock immediately, as if the lock screen timeout has |
| 2000 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2001 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2002 | * <p>The calling device admin must have requested |
| 2003 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 2004 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2005 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2006 | public void lockNow() { |
| 2007 | if (mService != null) { |
| 2008 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2009 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2010 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2011 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2015 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2016 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2017 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2018 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2019 | */ |
| 2020 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2021 | |
| 2022 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2023 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2024 | * data. |
| 2025 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2026 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2027 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2028 | */ |
| 2029 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2030 | |
| 2031 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 2032 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 2033 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2034 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2035 | * <p>The calling device admin must have requested |
| 2036 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 2037 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2038 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2039 | * @param flags Bit mask of additional options: currently supported flags |
| 2040 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 2041 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2042 | */ |
| 2043 | public void wipeData(int flags) { |
| 2044 | if (mService != null) { |
| 2045 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2046 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2047 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2048 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2049 | } |
| 2050 | } |
| 2051 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2052 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2053 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2054 | * Called by an application that is administering the device to set the |
| 2055 | * global proxy and exclusion list. |
| 2056 | * <p> |
| 2057 | * The calling device admin must have requested |
| 2058 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2059 | * this method; if it has not, a security exception will be thrown. |
| 2060 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2061 | * 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] | 2062 | * 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] | 2063 | * be returned. |
| 2064 | * The method can be called repeatedly by the device admin alrady setting the |
| 2065 | * proxy to update the proxy and exclusion list. |
| 2066 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2067 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2068 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2069 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2070 | * @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] | 2071 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2072 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2073 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2074 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2075 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2076 | List<String> exclusionList ) { |
| 2077 | if (proxySpec == null) { |
| 2078 | throw new NullPointerException(); |
| 2079 | } |
| 2080 | if (mService != null) { |
| 2081 | try { |
| 2082 | String hostSpec; |
| 2083 | String exclSpec; |
| 2084 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2085 | hostSpec = null; |
| 2086 | exclSpec = null; |
| 2087 | } else { |
| 2088 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2089 | throw new IllegalArgumentException(); |
| 2090 | } |
| 2091 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2092 | String hostName = sa.getHostName(); |
| 2093 | int port = sa.getPort(); |
| 2094 | StringBuilder hostBuilder = new StringBuilder(); |
| 2095 | hostSpec = hostBuilder.append(hostName) |
| 2096 | .append(":").append(Integer.toString(port)).toString(); |
| 2097 | if (exclusionList == null) { |
| 2098 | exclSpec = ""; |
| 2099 | } else { |
| 2100 | StringBuilder listBuilder = new StringBuilder(); |
| 2101 | boolean firstDomain = true; |
| 2102 | for (String exclDomain : exclusionList) { |
| 2103 | if (!firstDomain) { |
| 2104 | listBuilder = listBuilder.append(","); |
| 2105 | } else { |
| 2106 | firstDomain = false; |
| 2107 | } |
| 2108 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2109 | } |
| 2110 | exclSpec = listBuilder.toString(); |
| 2111 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2112 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2113 | != android.net.Proxy.PROXY_VALID) |
| 2114 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2115 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2116 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2117 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2118 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | return null; |
| 2122 | } |
| 2123 | |
| 2124 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2125 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 2126 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 2127 | * doing something unusual like general internal filtering this may be useful. On |
| 2128 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 2129 | * |
| 2130 | * <p>This method requires the caller to be the device owner. |
| 2131 | * |
| 2132 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 2133 | * @see ProxyInfo |
| 2134 | * |
| 2135 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2136 | * with. |
| 2137 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 2138 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 2139 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2140 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2141 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2142 | if (mService != null) { |
| 2143 | try { |
| 2144 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2145 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2146 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2147 | } |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2152 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2153 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2154 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2155 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2156 | */ |
| 2157 | public ComponentName getGlobalProxyAdmin() { |
| 2158 | if (mService != null) { |
| 2159 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2160 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2161 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2162 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2163 | } |
| 2164 | } |
| 2165 | return null; |
| 2166 | } |
| 2167 | |
| 2168 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2169 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2170 | * indicating that encryption is not supported. |
| 2171 | */ |
| 2172 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2173 | |
| 2174 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2175 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2176 | * indicating that encryption is supported, but is not currently active. |
| 2177 | */ |
| 2178 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2179 | |
| 2180 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2181 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2182 | * indicating that encryption is not currently active, but is currently |
| 2183 | * being activated. This is only reported by devices that support |
| 2184 | * encryption of data and only when the storage is currently |
| 2185 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2186 | * to become encrypted will never return this value. |
| 2187 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2188 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2189 | |
| 2190 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2191 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2192 | * indicating that encryption is active. |
| 2193 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2194 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2195 | |
| 2196 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2197 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2198 | * indicating that encryption is active, but an encryption key has not |
| 2199 | * been set by the user. |
| 2200 | */ |
| 2201 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2202 | |
| 2203 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2204 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2205 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2206 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2207 | * to check encryption status. However, on some devices this activity may never return, as |
| 2208 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2209 | */ |
| 2210 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2211 | public static final String ACTION_START_ENCRYPTION |
| 2212 | = "android.app.action.START_ENCRYPTION"; |
| 2213 | |
| 2214 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2215 | * Widgets are enabled in keyguard |
| 2216 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2217 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2218 | |
| 2219 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2220 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2221 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2222 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2223 | |
| 2224 | /** |
| 2225 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2226 | */ |
| 2227 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2228 | |
| 2229 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2230 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2231 | */ |
| 2232 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2233 | |
| 2234 | /** |
| 2235 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2236 | */ |
| 2237 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2238 | |
| 2239 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2240 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2241 | * (e.g. PIN/Pattern/Password). |
| 2242 | */ |
| 2243 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2244 | |
| 2245 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2246 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2247 | */ |
| 2248 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2249 | |
| 2250 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2251 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2252 | */ |
| 2253 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2254 | |
| 2255 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2256 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2257 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2258 | * |
| 2259 | * <p>When multiple device administrators attempt to control device |
| 2260 | * encryption, the most secure, supported setting will always be |
| 2261 | * used. If any device administrator requests device encryption, |
| 2262 | * it will be enabled; Conversely, if a device administrator |
| 2263 | * attempts to disable device encryption while another |
| 2264 | * device administrator has enabled it, the call to disable will |
| 2265 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2266 | * |
| 2267 | * <p>This policy controls encryption of the secure (application data) storage area. Data |
Andy Stadler | 50c294f | 2011-03-07 19:13:42 -0800 | [diff] [blame] | 2268 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2269 | * or control the encryption of any other storage areas. |
| 2270 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2271 | * {@code true}, then the directory returned by |
| 2272 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2273 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2274 | * |
| 2275 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2276 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2277 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2278 | * also require (and check for) a pattern, PIN, or password. |
| 2279 | * |
| 2280 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2281 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2282 | * @return the new request status (for all active admins) - will be one of |
| 2283 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2284 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2285 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2286 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2287 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2288 | if (mService != null) { |
| 2289 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2290 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2291 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2292 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2293 | } |
| 2294 | } |
| 2295 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2296 | } |
| 2297 | |
| 2298 | /** |
| 2299 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2300 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2301 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2302 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2303 | * this will return the requested encryption setting as an aggregate of all active |
| 2304 | * administrators. |
| 2305 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2306 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2307 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2308 | if (mService != null) { |
| 2309 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2310 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2311 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2312 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2313 | } |
| 2314 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2315 | return false; |
| 2316 | } |
| 2317 | |
| 2318 | /** |
| 2319 | * Called by an application that is administering the device to |
| 2320 | * determine the current encryption status of the device. |
| 2321 | * |
| 2322 | * Depending on the returned status code, the caller may proceed in different |
| 2323 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2324 | * storage system does not support encryption. If the |
| 2325 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2326 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2327 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2328 | * storage system has enabled encryption but no password is set so further action |
| 2329 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2330 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2331 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2332 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2333 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2334 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2335 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2336 | */ |
| 2337 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2338 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | /** @hide per-user version */ |
| 2342 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2343 | if (mService != null) { |
| 2344 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2345 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2346 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2347 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2348 | } |
| 2349 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2350 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2351 | } |
| 2352 | |
| 2353 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2354 | * Installs the given certificate as a user CA. |
| 2355 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2356 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2357 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2358 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2359 | * |
| 2360 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2361 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2362 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2363 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2364 | if (mService != null) { |
| 2365 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2366 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2367 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2368 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2369 | } |
| 2370 | } |
| 2371 | return false; |
| 2372 | } |
| 2373 | |
| 2374 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2375 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2376 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2377 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2378 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2379 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2380 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2381 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2382 | if (mService != null) { |
| 2383 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2384 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2385 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2386 | } catch (CertificateException e) { |
| 2387 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2388 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2389 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2395 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2396 | * If a user has installed any certificates by other means than device policy these will be |
| 2397 | * included too. |
| 2398 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2399 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2400 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2401 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2402 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2403 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2404 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2405 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2406 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2407 | mService.enforceCanManageCaCerts(admin); |
| 2408 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2409 | for (String alias : certStore.userAliases()) { |
| 2410 | try { |
| 2411 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2412 | } catch (CertificateException ce) { |
| 2413 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2414 | } |
| 2415 | } |
| 2416 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2417 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2418 | } |
| 2419 | } |
| 2420 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2424 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2425 | * means other than device policy will also be removed, except for system CA certificates. |
| 2426 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2427 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2428 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2429 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2430 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2431 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2432 | try { |
| 2433 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2434 | .toArray(new String[0])); |
| 2435 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2436 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2437 | } |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | /** |
| 2442 | * Returns whether this certificate is installed as a trusted CA. |
| 2443 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2444 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2445 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2446 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2447 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2448 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2449 | if (mService != null) { |
| 2450 | try { |
| 2451 | mService.enforceCanManageCaCerts(admin); |
| 2452 | return getCaCertAlias(certBuffer) != null; |
| 2453 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2454 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2455 | } catch (CertificateException ce) { |
| 2456 | Log.w(TAG, "Could not parse certificate", ce); |
| 2457 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2458 | } |
| 2459 | return false; |
| 2460 | } |
| 2461 | |
| 2462 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2463 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 2464 | * keypair will be visible to all apps within the profile. |
| 2465 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2466 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2467 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2468 | * @param privKey The private key to install. |
| 2469 | * @param cert The certificate to install. |
| 2470 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2471 | * with that alias already exists, it will be overwritten. |
| 2472 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2473 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2474 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2475 | @NonNull Certificate cert, @NonNull String alias) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2476 | try { |
| 2477 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2478 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2479 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2480 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2481 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2482 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2483 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2484 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2485 | } catch (CertificateException | IOException e) { |
| 2486 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2487 | } |
| 2488 | return false; |
| 2489 | } |
| 2490 | |
| 2491 | /** |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2492 | * Called by a device or profile owner to remove all user credentials installed under a given |
| 2493 | * alias. |
| 2494 | * |
| 2495 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2496 | * {@code null} if calling from a delegated certificate installer. |
| 2497 | * @param alias The private key alias under which the certificate is installed. |
| 2498 | * @return {@code true} if the keys were both removed, {@code false} otherwise. |
| 2499 | */ |
| 2500 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2501 | try { |
| 2502 | return mService.removeKeyPair(admin, alias); |
| 2503 | } catch (RemoteException e) { |
| 2504 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2505 | } |
| 2506 | return false; |
| 2507 | } |
| 2508 | |
| 2509 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2510 | * @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] | 2511 | * doesn't exist. |
| 2512 | */ |
| 2513 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2514 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2515 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2516 | new ByteArrayInputStream(certBuffer)); |
| 2517 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2518 | } |
| 2519 | |
| 2520 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2521 | * 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] | 2522 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2523 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2524 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2525 | * <p> |
| 2526 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2527 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2528 | * installer. |
| 2529 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2530 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2531 | * @param installerPackage The package name of the certificate installer which will be given |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2532 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2533 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2534 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2535 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2536 | if (mService != null) { |
| 2537 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2538 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2539 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2540 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | /** |
| 2546 | * Called by a profile owner or device owner to retrieve the certificate installer for the |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2547 | * user. null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2548 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2549 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2550 | * @return The package name of the current delegated certificate installer, or {@code null} |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2551 | * if none is set. |
| 2552 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2553 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2554 | if (mService != null) { |
| 2555 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2556 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2557 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2558 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2559 | } |
| 2560 | } |
| 2561 | return null; |
| 2562 | } |
| 2563 | |
| 2564 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2565 | * Called by a device or profile owner to configure an always-on VPN connection through a |
| 2566 | * specific application for the current user. |
| 2567 | * This connection is automatically granted and persisted after a reboot. |
| 2568 | * |
| 2569 | * <p>The designated package should declare a {@link android.net.VpnService} in its |
| 2570 | * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, |
| 2571 | * otherwise the call will fail. |
| 2572 | * |
| 2573 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} |
| 2574 | * to remove an existing always-on VPN configuration. |
| 2575 | * |
| 2576 | * @return {@code true} if the package is set as always-on VPN controller; |
| 2577 | * {@code false} otherwise. |
| 2578 | */ |
| 2579 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2580 | @Nullable String vpnPackage) { |
| 2581 | if (mService != null) { |
| 2582 | try { |
| 2583 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2584 | } catch (RemoteException e) { |
| 2585 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2586 | } |
| 2587 | } |
| 2588 | return false; |
| 2589 | } |
| 2590 | |
| 2591 | /** |
| 2592 | * Called by a device or profile owner to read the name of the package administering an |
| 2593 | * always-on VPN connection for the current user. |
| 2594 | * If there is no such package, or the always-on VPN is provided by the system instead |
| 2595 | * of by an application, {@code null} will be returned. |
| 2596 | * |
| 2597 | * @return Package name of VPN controller responsible for always-on VPN, |
| 2598 | * or {@code null} if none is set. |
| 2599 | */ |
| 2600 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2601 | if (mService != null) { |
| 2602 | try { |
| 2603 | return mService.getAlwaysOnVpnPackage(admin); |
| 2604 | } catch (RemoteException e) { |
| 2605 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2606 | } |
| 2607 | } |
| 2608 | return null; |
| 2609 | } |
| 2610 | |
| 2611 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2612 | * Called by an application that is administering the device to disable all cameras |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2613 | * on the device, for this user. After setting this, no applications running as this user |
| 2614 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2615 | * |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 2616 | * <p>If the caller is device owner, then the restriction will be applied to all users. |
| 2617 | * |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2618 | * <p>The calling device admin must have requested |
| 2619 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2620 | * this method; if it has not, a security exception will be thrown. |
| 2621 | * |
| 2622 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2623 | * @param disabled Whether or not the camera should be disabled. |
| 2624 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2625 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2626 | if (mService != null) { |
| 2627 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2628 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2629 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2630 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2636 | * 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] | 2637 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2638 | * @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] | 2639 | * have disabled the camera |
| 2640 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2641 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2642 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2646 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2647 | if (mService != null) { |
| 2648 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2649 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2650 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2651 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2652 | } |
| 2653 | } |
| 2654 | return false; |
| 2655 | } |
| 2656 | |
| 2657 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2658 | * Called by a device owner to request a bugreport. |
| 2659 | * |
| 2660 | * <p>There must be only one user on the device, managed by the device owner. |
| 2661 | * Otherwise a security exception will be thrown. |
| 2662 | * |
| 2663 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2664 | * @return {@code true} if the bugreport collection started successfully, or {@code false} |
| 2665 | * if it wasn't triggered because a previous bugreport operation is still active |
| 2666 | * (either the bugreport is still running or waiting for the user to share or decline) |
| 2667 | */ |
| 2668 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 2669 | if (mService != null) { |
| 2670 | try { |
| 2671 | return mService.requestBugreport(admin); |
| 2672 | } catch (RemoteException e) { |
| 2673 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2674 | } |
| 2675 | } |
| 2676 | return false; |
| 2677 | } |
| 2678 | |
| 2679 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2680 | * Determine whether or not creating a guest user has been disabled for the device |
| 2681 | * |
| 2682 | * @hide |
| 2683 | */ |
| 2684 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 2685 | // Currently guest users can always be created if multi-user is enabled |
| 2686 | // TODO introduce a policy for guest user creation |
| 2687 | return false; |
| 2688 | } |
| 2689 | |
| 2690 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2691 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2692 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2693 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2694 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2695 | * |
| 2696 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2697 | * security exception will be thrown. |
| 2698 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2699 | * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 2700 | * blocks assist requests for all activities of the relevant user. |
| 2701 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2702 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2703 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2704 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2705 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2706 | if (mService != null) { |
| 2707 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2708 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2709 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2710 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2716 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2717 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2718 | * @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] | 2719 | * have disabled screen capture. |
| 2720 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2721 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2722 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2726 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2727 | if (mService != null) { |
| 2728 | try { |
| 2729 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2730 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2731 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2732 | } |
| 2733 | } |
| 2734 | return false; |
| 2735 | } |
| 2736 | |
| 2737 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2738 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2739 | * required the user cannot set the date and time, but has to use network date and time. |
| 2740 | * |
| 2741 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2742 | * |
| 2743 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2744 | * be thrown. |
| 2745 | * |
| 2746 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2747 | * @param required Whether auto time is set required or not. |
| 2748 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2749 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2750 | if (mService != null) { |
| 2751 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2752 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2753 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2754 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2755 | } |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | /** |
| 2760 | * @return true if auto time is required. |
| 2761 | */ |
| 2762 | public boolean getAutoTimeRequired() { |
| 2763 | if (mService != null) { |
| 2764 | try { |
| 2765 | return mService.getAutoTimeRequired(); |
| 2766 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2767 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2768 | } |
| 2769 | } |
| 2770 | return false; |
| 2771 | } |
| 2772 | |
| 2773 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 2774 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
| 2775 | * |
| 2776 | * <p>The system user is exempt from this policy - it is never ephemeral. |
| 2777 | * |
| 2778 | * <p>The calling device admin must be the device owner. If it is not, a security exception will |
| 2779 | * be thrown. |
| 2780 | * |
| 2781 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2782 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
| 2783 | * subsequently created users will be ephemeral. |
| 2784 | * @hide |
| 2785 | */ |
| 2786 | public void setForceEphemeralUsers( |
| 2787 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 2788 | if (mService != null) { |
| 2789 | try { |
| 2790 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 2791 | } catch (RemoteException e) { |
| 2792 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2793 | } |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | /** |
| 2798 | * @return true if all users are created ephemeral. |
| 2799 | * @hide |
| 2800 | */ |
| 2801 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 2802 | if (mService != null) { |
| 2803 | try { |
| 2804 | return mService.getForceEphemeralUsers(admin); |
| 2805 | } catch (RemoteException e) { |
| 2806 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2807 | } |
| 2808 | } |
| 2809 | return false; |
| 2810 | } |
| 2811 | |
| 2812 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2813 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2814 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2815 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2816 | * |
| 2817 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2818 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2819 | * this method; if it has not, a security exception will be thrown. |
| 2820 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2821 | * <p>Calling this from a managed profile before version |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2822 | * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2823 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2824 | * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2825 | * <ul> |
| 2826 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT} |
| 2827 | * these will affect the profile's parent user. |
| 2828 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications |
| 2829 | * generated by applications in the managed profile. |
| 2830 | * </ul> |
| 2831 | * <p>Requests to disable other features on a managed profile will be ignored. The admin |
| 2832 | * can check which features have been disabled by calling |
| 2833 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2834 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2835 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2836 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2837 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2838 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2839 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 2840 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2841 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2842 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2843 | if (mService != null) { |
| 2844 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2845 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2846 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2847 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2848 | } |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2853 | * Determine whether or not features have been disabled in keyguard either by the calling |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2854 | * admin, if specified, or all admins. |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2855 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 2856 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2857 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2858 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2859 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2860 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2861 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2865 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2866 | if (mService != null) { |
| 2867 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2868 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2869 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2870 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2871 | } |
| 2872 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2873 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2877 | * @hide |
| 2878 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2879 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 2880 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2881 | if (mService != null) { |
| 2882 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2883 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2884 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2885 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2886 | } |
| 2887 | } |
| 2888 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2889 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2890 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2891 | * @hide |
| 2892 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2893 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2894 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2898 | * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2899 | * @hide |
| 2900 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2901 | public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2902 | ActivityInfo ai; |
| 2903 | try { |
| 2904 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2905 | PackageManager.GET_META_DATA); |
| 2906 | } catch (PackageManager.NameNotFoundException e) { |
| 2907 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2908 | return null; |
| 2909 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2910 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2911 | ResolveInfo ri = new ResolveInfo(); |
| 2912 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2913 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2914 | try { |
| 2915 | return new DeviceAdminInfo(mContext, ri); |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2916 | } catch (XmlPullParserException | IOException e) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2917 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2918 | return null; |
| 2919 | } |
| 2920 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2921 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2922 | /** |
| 2923 | * @hide |
| 2924 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2925 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2926 | if (mService != null) { |
| 2927 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2928 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2929 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2930 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2931 | } |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | /** |
| 2936 | * @hide |
| 2937 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2938 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2939 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2940 | if (mService != null) { |
| 2941 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2942 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2943 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2944 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2945 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2949 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2950 | /** |
| 2951 | * @hide |
| 2952 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2953 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2954 | if (mService != null) { |
| 2955 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2956 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2957 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2958 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2959 | } |
| 2960 | } |
| 2961 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2962 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2963 | /** |
| 2964 | * @hide |
| 2965 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2966 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2967 | if (mService != null) { |
| 2968 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2969 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2970 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2971 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2972 | } |
| 2973 | } |
| 2974 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2975 | |
| 2976 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 2977 | * Should be called when keyguard has been dismissed. |
| 2978 | * @hide |
| 2979 | */ |
| 2980 | public void reportKeyguardDismissed() { |
| 2981 | if (mService != null) { |
| 2982 | try { |
| 2983 | mService.reportKeyguardDismissed(); |
| 2984 | } catch (RemoteException e) { |
| 2985 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2986 | } |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | /** |
| 2991 | * Should be called when keyguard view has been shown to the user. |
| 2992 | * @hide |
| 2993 | */ |
| 2994 | public void reportKeyguardSecured() { |
| 2995 | if (mService != null) { |
| 2996 | try { |
| 2997 | mService.reportKeyguardSecured(); |
| 2998 | } catch (RemoteException e) { |
| 2999 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3000 | } |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3005 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3006 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3007 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3008 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3009 | * @return whether the package was successfully registered as the device owner. |
| 3010 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3011 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3012 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3013 | public boolean setDeviceOwner(ComponentName who) { |
| 3014 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | /** |
| 3018 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3019 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3020 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3021 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | /** |
| 3025 | * @hide |
| 3026 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3027 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3028 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | /** |
| 3032 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3033 | * Sets the given package as the device owner. The package must already be installed. There |
| 3034 | * must not already be a device owner. |
| 3035 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3036 | * this method. |
| 3037 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3038 | * 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] | 3039 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3040 | * @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] | 3041 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3042 | * @return whether the package was successfully registered as the device owner. |
| 3043 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3044 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3045 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3046 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3047 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3048 | if (mService != null) { |
| 3049 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3050 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3051 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3052 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3053 | } |
| 3054 | } |
| 3055 | return false; |
| 3056 | } |
| 3057 | |
| 3058 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3059 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3060 | * 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] | 3061 | * 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] | 3062 | * package is currently registered as the device owner app, pass in the package name from |
| 3063 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3064 | * 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] | 3065 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3066 | * the setup process. |
| 3067 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3068 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3069 | * @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] | 3070 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3071 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3072 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3073 | } |
| 3074 | |
| 3075 | /** |
| 3076 | * @return true if a package is registered as device owner, only when it's running on the |
| 3077 | * calling user. |
| 3078 | * |
| 3079 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3080 | * @hide |
| 3081 | */ |
| 3082 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3083 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3084 | } |
| 3085 | |
| 3086 | /** |
| 3087 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3088 | * user. |
| 3089 | * |
| 3090 | * <p>Requires the MANAGE_USERS permission. |
| 3091 | * |
| 3092 | * @hide |
| 3093 | */ |
| 3094 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3095 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3096 | } |
| 3097 | |
| 3098 | /** |
| 3099 | * @return device owner component name, only when it's running on the calling user. |
| 3100 | * |
| 3101 | * @hide |
| 3102 | */ |
| 3103 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3104 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3105 | } |
| 3106 | |
| 3107 | /** |
| 3108 | * @return device owner component name, even if it's running on a different user. |
| 3109 | * |
| 3110 | * <p>Requires the MANAGE_USERS permission. |
| 3111 | * |
| 3112 | * @hide |
| 3113 | */ |
| 3114 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3115 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3116 | } |
| 3117 | |
| 3118 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3119 | if (packageName == null) { |
| 3120 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3121 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3122 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3123 | if (deviceOwner == null) { |
| 3124 | return false; |
| 3125 | } |
| 3126 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3129 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3130 | if (mService != null) { |
| 3131 | try { |
| 3132 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3133 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3134 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3140 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3141 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3142 | * no device owner. |
| 3143 | * |
| 3144 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3145 | * |
| 3146 | * @hide |
| 3147 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3148 | public int getDeviceOwnerUserId() { |
| 3149 | if (mService != null) { |
| 3150 | try { |
| 3151 | return mService.getDeviceOwnerUserId(); |
| 3152 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3153 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3154 | } |
| 3155 | } |
| 3156 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | /** |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3160 | * Clears the current device owner. The caller must be the device owner. |
| 3161 | * |
| 3162 | * This function should be used cautiously as once it is called it cannot |
| 3163 | * be undone. The device owner can only be set as a part of device setup |
| 3164 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3165 | * |
| 3166 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3167 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3168 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3169 | if (mService != null) { |
| 3170 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3171 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3172 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3173 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3178 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3179 | * Returns the device owner package name, only if it's running on the calling user. |
| 3180 | * |
| 3181 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3182 | * |
| 3183 | * @hide |
| 3184 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3185 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3186 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3187 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3188 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3192 | * @return true if the device is managed by any device owner. |
| 3193 | * |
| 3194 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3195 | * |
| 3196 | * @hide |
| 3197 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3198 | public boolean isDeviceManaged() { |
| 3199 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3200 | } |
| 3201 | |
| 3202 | /** |
| 3203 | * Returns the device owner name. Note this method *will* return the device owner |
| 3204 | * name when it's running on a different user. |
| 3205 | * |
| 3206 | * <p>Requires the MANAGE_USERS permission. |
| 3207 | * |
| 3208 | * @hide |
| 3209 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3210 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3211 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3212 | if (mService != null) { |
| 3213 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3214 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3215 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3216 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | return null; |
| 3220 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3221 | |
| 3222 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3223 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3224 | * @deprecated Do not use |
| 3225 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3226 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3227 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3228 | @SystemApi |
| 3229 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3230 | return null; |
| 3231 | } |
| 3232 | |
| 3233 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3234 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3235 | * @deprecated Do not use |
| 3236 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3237 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3238 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3239 | @SystemApi |
| 3240 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3241 | return null; |
| 3242 | } |
| 3243 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3244 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3245 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3246 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3247 | * Sets the given component as an active admin and registers the package as the profile |
| 3248 | * owner for this user. The package must already be installed and there shouldn't be |
| 3249 | * an existing profile owner registered for this user. Also, this method must be called |
| 3250 | * before the user setup has been completed. |
| 3251 | * <p> |
| 3252 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3253 | * MANAGE_DEVICE_ADMINS permission. |
| 3254 | * @param admin The component to register as an active admin and profile owner. |
| 3255 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3256 | * @return whether the admin was successfully registered as the profile owner. |
| 3257 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3258 | * the user has already been set up. |
| 3259 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3260 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3261 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3262 | throws IllegalArgumentException { |
| 3263 | if (mService != null) { |
| 3264 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3265 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3266 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3267 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3268 | } catch (RemoteException re) { |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3269 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3270 | } |
| 3271 | } |
| 3272 | return false; |
| 3273 | } |
| 3274 | |
| 3275 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3276 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 3277 | * be from the same package as the active profile owner for this user, otherwise a |
| 3278 | * SecurityException will be thrown. |
| 3279 | * |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3280 | * <p>This doesn't work for managed profile owners. |
| 3281 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3282 | * @param admin The component to remove as the profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3283 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3284 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3285 | if (mService != null) { |
| 3286 | try { |
| 3287 | mService.clearProfileOwner(admin); |
| 3288 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3289 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3290 | } |
| 3291 | } |
| 3292 | } |
| 3293 | |
| 3294 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3295 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3296 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3297 | */ |
| 3298 | public boolean hasUserSetupCompleted() { |
| 3299 | if (mService != null) { |
| 3300 | try { |
| 3301 | return mService.hasUserSetupCompleted(); |
| 3302 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3303 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3304 | } |
| 3305 | } |
| 3306 | return true; |
| 3307 | } |
| 3308 | |
| 3309 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3310 | * @hide |
| 3311 | * 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] | 3312 | * already be installed. There must not already be a profile owner for this user. |
| 3313 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3314 | * this method. |
| 3315 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3316 | * - the caller is SYSTEM_UID. |
| 3317 | * - 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] | 3318 | * @param admin the component name to be registered as profile owner. |
| 3319 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3320 | * @param userHandle the userId to set the profile owner for. |
| 3321 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3322 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3323 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3324 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3325 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3326 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3327 | if (mService != null) { |
| 3328 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3329 | if (ownerName == null) { |
| 3330 | ownerName = ""; |
| 3331 | } |
| 3332 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3333 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3334 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3335 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3336 | } |
| 3337 | } |
| 3338 | return false; |
| 3339 | } |
| 3340 | |
| 3341 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3342 | * Sets the device owner information to be shown on the lock screen. |
| 3343 | * |
| 3344 | * <p>If the device owner information is {@code null} or empty then the device owner info is |
| 3345 | * cleared and the user owner info is shown on the lock screen if it is set. |
Andrei Stingaceanu | cc5061f | 2016-01-07 17:55:57 +0000 | [diff] [blame] | 3346 | * <p>If the device owner information contains only whitespaces then the message on the lock |
| 3347 | * screen will be blank and the user will not be allowed to change it. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3348 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame^] | 3349 | * <p>If the device owner information needs to be localized, it is the responsibility of the |
| 3350 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3351 | * and set a new version of this string accordingly. |
| 3352 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3353 | * @param admin The name of the admin component to check. |
| 3354 | * @param info Device owner information which will be displayed instead of the user |
| 3355 | * owner info. |
| 3356 | * @return Whether the device owner information has been set. |
| 3357 | */ |
| 3358 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3359 | if (mService != null) { |
| 3360 | try { |
| 3361 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3362 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3363 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3364 | } |
| 3365 | } |
| 3366 | return false; |
| 3367 | } |
| 3368 | |
| 3369 | /** |
| 3370 | * @return The device owner information. If it is not set returns {@code null}. |
| 3371 | */ |
| 3372 | public String getDeviceOwnerLockScreenInfo() { |
| 3373 | if (mService != null) { |
| 3374 | try { |
| 3375 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3376 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3377 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3378 | } |
| 3379 | } |
| 3380 | return null; |
| 3381 | } |
| 3382 | |
| 3383 | /** |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3384 | * Called by device or profile owners for setting the package suspended for this user. |
| 3385 | * A suspended package will not be started by the package manager, its notifications will |
| 3386 | * be hidden and it will not show up in recents. The package must already be installed. |
| 3387 | * |
| 3388 | * @param admin The name of the admin component to check. |
| 3389 | * @param packageName The package name of the app to suspend or unsuspend. |
| 3390 | * @param suspended If set to {@code true} than the package will be suspended, if set to |
| 3391 | * {@code false} the package will be unsuspended. |
| 3392 | * @return boolean {@code true} if the operation was successfully performed, {@code false} |
| 3393 | * otherwise. |
| 3394 | */ |
| 3395 | public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName, |
| 3396 | boolean suspended) { |
| 3397 | if (mService != null) { |
| 3398 | try { |
| 3399 | return mService.setPackageSuspended(admin, packageName, suspended); |
| 3400 | } catch (RemoteException re) { |
| 3401 | Log.w(TAG, "Failed talking with device policy service", re); |
| 3402 | } |
| 3403 | } |
| 3404 | return false; |
| 3405 | } |
| 3406 | |
| 3407 | /** |
| 3408 | * Called by device or profile owners to determine if a package is suspended. |
| 3409 | * |
| 3410 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3411 | * @param packageName The name of the package to retrieve the suspended status of. |
| 3412 | * @return boolean {@code true} if the package is suspended, {@code false} otherwise. |
| 3413 | */ |
| 3414 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3415 | if (mService != null) { |
| 3416 | try { |
| 3417 | return mService.getPackageSuspended(admin, packageName); |
| 3418 | } catch (RemoteException e) { |
| 3419 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3420 | } |
| 3421 | } |
| 3422 | return false; |
| 3423 | } |
| 3424 | |
| 3425 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3426 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3427 | * be used. Only the profile owner can call this. |
| 3428 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3429 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3430 | * |
| 3431 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3432 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3433 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3434 | if (mService != null) { |
| 3435 | try { |
| 3436 | mService.setProfileEnabled(admin); |
| 3437 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3438 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3444 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3445 | * which it is called from. Only a profile owner or device owner can call this. If this is |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3446 | * never called by the profile or device owner, the name will be set to default values. |
| 3447 | * |
| 3448 | * @see #isProfileOwnerApp |
| 3449 | * @see #isDeviceOwnerApp |
| 3450 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3451 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3452 | * @param profileName The name of the profile. |
| 3453 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3454 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3455 | if (mService != null) { |
| 3456 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3457 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3458 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3459 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3460 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3461 | } |
| 3462 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3463 | |
| 3464 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3465 | * 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] | 3466 | * 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] | 3467 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3468 | * |
| 3469 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3470 | * @return Whether or not the package is registered as the profile owner. |
| 3471 | */ |
| 3472 | public boolean isProfileOwnerApp(String packageName) { |
| 3473 | if (mService != null) { |
| 3474 | try { |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3475 | ComponentName profileOwner = mService.getProfileOwner( |
| 3476 | Process.myUserHandle().getIdentifier()); |
| 3477 | return profileOwner != null |
| 3478 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3479 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3480 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3481 | } |
| 3482 | } |
| 3483 | return false; |
| 3484 | } |
| 3485 | |
| 3486 | /** |
| 3487 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3488 | * @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] | 3489 | * owner has been set for that user. |
| 3490 | * @throws IllegalArgumentException if the userId is invalid. |
| 3491 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3492 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3493 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3494 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3495 | } |
| 3496 | |
| 3497 | /** |
| 3498 | * @see #getProfileOwner() |
| 3499 | * @hide |
| 3500 | */ |
| 3501 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3502 | if (mService != null) { |
| 3503 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3504 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3505 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3506 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3507 | throw new IllegalArgumentException( |
| 3508 | "Requested profile owner for invalid userId", re); |
| 3509 | } |
| 3510 | } |
| 3511 | return null; |
| 3512 | } |
| 3513 | |
| 3514 | /** |
| 3515 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3516 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3517 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3518 | * @throws IllegalArgumentException if the userId is invalid. |
| 3519 | */ |
| 3520 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3521 | if (mService != null) { |
| 3522 | try { |
| 3523 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3524 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3525 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3526 | throw new IllegalArgumentException( |
| 3527 | "Requested profile owner for invalid userId", re); |
| 3528 | } |
| 3529 | } |
| 3530 | return null; |
| 3531 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3532 | |
| 3533 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3534 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3535 | * @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] | 3536 | * @return the human readable name of the organisation associated with this profile owner or |
| 3537 | * null if one is not set. |
| 3538 | * @throws IllegalArgumentException if the userId is invalid. |
| 3539 | */ |
| 3540 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3541 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3542 | if (mService != null) { |
| 3543 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3544 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3545 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3546 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3547 | throw new IllegalArgumentException( |
| 3548 | "Requested profile owner for invalid userId", re); |
| 3549 | } |
| 3550 | } |
| 3551 | return null; |
| 3552 | } |
| 3553 | |
| 3554 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3555 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3556 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3557 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3558 | * the intent preferences are reset. |
| 3559 | * |
| 3560 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3561 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3562 | * intent handler for the filter. |
| 3563 | * |
| 3564 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3565 | * security exception will be thrown. |
| 3566 | * |
| 3567 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3568 | * @param filter The IntentFilter for which a default handler is added. |
| 3569 | * @param activity The Activity that is added as default intent handler. |
| 3570 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3571 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3572 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3573 | if (mService != null) { |
| 3574 | try { |
| 3575 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3576 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3577 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3578 | } |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | /** |
| 3583 | * 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] | 3584 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3585 | * |
| 3586 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3587 | * exception will be thrown. |
| 3588 | * |
| 3589 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3590 | * @param packageName The name of the package for which preferences are removed. |
| 3591 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3592 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3593 | String packageName) { |
| 3594 | if (mService != null) { |
| 3595 | try { |
| 3596 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3597 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3598 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3602 | |
| 3603 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3604 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 3605 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 3606 | * {@link #getApplicationRestrictions}. |
| 3607 | * <p> |
| 3608 | * This permission is persistent until it is later cleared by calling this method with a |
| 3609 | * {@code null} value or uninstalling the managing package. |
| 3610 | * |
| 3611 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3612 | * @param packageName The package name which will be given access to application restrictions |
| 3613 | * APIs. If {@code null} is given the current package will be cleared. |
| 3614 | */ |
| 3615 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
| 3616 | @Nullable String packageName) { |
| 3617 | if (mService != null) { |
| 3618 | try { |
| 3619 | mService.setApplicationRestrictionsManagingPackage(admin, packageName); |
| 3620 | } catch (RemoteException e) { |
| 3621 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3622 | } |
| 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 3628 | * package for the current user, or {@code null} if none is set. |
| 3629 | * |
| 3630 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3631 | * @return The package name allowed to manage application restrictions on the current user, or |
| 3632 | * {@code null} if none is set. |
| 3633 | */ |
| 3634 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 3635 | if (mService != null) { |
| 3636 | try { |
| 3637 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 3638 | } catch (RemoteException e) { |
| 3639 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3640 | } |
| 3641 | } |
| 3642 | return null; |
| 3643 | } |
| 3644 | |
| 3645 | /** |
| 3646 | * Returns {@code true} if the calling package has been granted permission via |
| 3647 | * {@link #setApplicationRestrictionsManagingPackage} to manage application |
| 3648 | * restrictions for the calling user. |
| 3649 | */ |
| 3650 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 3651 | if (mService != null) { |
| 3652 | try { |
| 3653 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 3654 | } catch (RemoteException e) { |
| 3655 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3656 | } |
| 3657 | } |
| 3658 | return false; |
| 3659 | } |
| 3660 | |
| 3661 | /** |
| 3662 | * Sets the application restrictions for a given target application running in the calling user. |
| 3663 | * |
| 3664 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 3665 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 3666 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3667 | * |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 3668 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
| 3669 | * <ul> |
| 3670 | * <li>{@code boolean} |
| 3671 | * <li>{@code int} |
| 3672 | * <li>{@code String} or {@code String[]} |
| 3673 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 3674 | * </ul> |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3675 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3676 | * <p>If the restrictions are not available yet, but may be applied in the near future, |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3677 | * the caller can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3678 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 3679 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3680 | * <p>The application restrictions are only made visible to the target application via |
| 3681 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or |
| 3682 | * device owner, and the application restrictions managing package via |
| 3683 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3684 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3686 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3687 | * @param packageName The name of the package to update restricted settings for. |
| 3688 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 3689 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3690 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3691 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3692 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3693 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3694 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3695 | Bundle settings) { |
| 3696 | if (mService != null) { |
| 3697 | try { |
| 3698 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3699 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3700 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3701 | } |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3706 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3707 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3708 | * trust agents but those enabled by this function call. If flag |
| 3709 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3710 | * |
| 3711 | * <p>The calling device admin must have requested |
| 3712 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3713 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3714 | * |
| 3715 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3716 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3717 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3718 | * will be strictly disabled according to the state of the |
| 3719 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 3720 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 3721 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 3722 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3723 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3724 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 3725 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3726 | if (mService != null) { |
| 3727 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3728 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3729 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3730 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3731 | } |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3736 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 3737 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 3738 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3739 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3740 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3741 | * this function returns a list of configurations for all admins that declare |
| 3742 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 3743 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 3744 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 3745 | * 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] | 3746 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3747 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3748 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3749 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3750 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3751 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3755 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3756 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3757 | if (mService != null) { |
| 3758 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3759 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3760 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3761 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3762 | } |
| 3763 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3764 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3768 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 3769 | * the managed profile will be shown in the parent profile, for incoming calls. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3770 | * |
| 3771 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3772 | * security exception will be thrown. |
| 3773 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3774 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3775 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 3776 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3777 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3778 | if (mService != null) { |
| 3779 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3780 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3781 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3782 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3783 | } |
| 3784 | } |
| 3785 | } |
| 3786 | |
| 3787 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3788 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 3789 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3790 | * |
| 3791 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3792 | * security exception will be thrown. |
| 3793 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3794 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3795 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3796 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3797 | if (mService != null) { |
| 3798 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3799 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3800 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3801 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3802 | } |
| 3803 | } |
| 3804 | return false; |
| 3805 | } |
| 3806 | |
| 3807 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3808 | * Determine whether or not caller-Id information has been disabled. |
| 3809 | * |
| 3810 | * @param userHandle The user for whom to check the caller-id permission |
| 3811 | * @hide |
| 3812 | */ |
| 3813 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 3814 | if (mService != null) { |
| 3815 | try { |
| 3816 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 3817 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3818 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3819 | } |
| 3820 | } |
| 3821 | return false; |
| 3822 | } |
| 3823 | |
| 3824 | /** |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 3825 | * Called by a profile owner of a managed profile to set whether contacts search from |
| 3826 | * the managed profile will be shown in the parent profile, for incoming calls. |
| 3827 | * |
| 3828 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3829 | * security exception will be thrown. |
| 3830 | * |
| 3831 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3832 | * @param disabled If true contacts search in the managed profile is not displayed. |
| 3833 | */ |
| 3834 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 3835 | boolean disabled) { |
| 3836 | if (mService != null) { |
| 3837 | try { |
| 3838 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 3839 | } catch (RemoteException e) { |
| 3840 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3841 | } |
| 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | /** |
| 3846 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 3847 | * has been disabled. |
| 3848 | * |
| 3849 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3850 | * security exception will be thrown. |
| 3851 | * |
| 3852 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3853 | */ |
| 3854 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 3855 | if (mService != null) { |
| 3856 | try { |
| 3857 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 3858 | } catch (RemoteException e) { |
| 3859 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3860 | } |
| 3861 | } |
| 3862 | return false; |
| 3863 | } |
| 3864 | |
| 3865 | |
| 3866 | /** |
| 3867 | * Determine whether or not contacts search has been disabled. |
| 3868 | * |
| 3869 | * @param userHandle The user for whom to check the contacts search permission |
| 3870 | * @hide |
| 3871 | */ |
| 3872 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 3873 | if (mService != null) { |
| 3874 | try { |
| 3875 | return mService |
| 3876 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 3877 | } catch (RemoteException e) { |
| 3878 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3879 | } |
| 3880 | } |
| 3881 | return false; |
| 3882 | } |
| 3883 | |
| 3884 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3885 | * 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] | 3886 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3887 | * @hide |
| 3888 | */ |
| 3889 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3890 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3891 | if (mService != null) { |
| 3892 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3893 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 3894 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3895 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3896 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3897 | } |
| 3898 | } |
| 3899 | } |
| 3900 | |
| 3901 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3902 | * 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] | 3903 | * @hide |
| 3904 | */ |
| 3905 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 3906 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3907 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 3908 | originalIntent); |
| 3909 | } |
| 3910 | |
| 3911 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3912 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 3913 | * devices can access enterprise contacts. |
| 3914 | * <p> |
| 3915 | * The calling device admin must be a profile owner. If it is not, a |
| 3916 | * security exception will be thrown. |
| 3917 | * <p> |
| 3918 | * This API works on managed profile only. |
| 3919 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3920 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3921 | * with. |
| 3922 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 3923 | * contacts. |
| 3924 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3925 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3926 | if (mService != null) { |
| 3927 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3928 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3929 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3930 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3931 | } |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | /** |
| 3936 | * Called by a profile owner of a managed profile to determine whether or |
| 3937 | * not Bluetooth devices cannot access enterprise contacts. |
| 3938 | * <p> |
| 3939 | * The calling device admin must be a profile owner. If it is not, a |
| 3940 | * security exception will be thrown. |
| 3941 | * <p> |
| 3942 | * This API works on managed profile only. |
| 3943 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3944 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3945 | * with. |
| 3946 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3947 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3948 | if (mService != null) { |
| 3949 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3950 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3951 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3952 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3953 | } |
| 3954 | } |
| 3955 | return true; |
| 3956 | } |
| 3957 | |
| 3958 | /** |
| 3959 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 3960 | * <p> |
| 3961 | * This API works on managed profile UserHandle only. |
| 3962 | * |
| 3963 | * @param userHandle The user for whom to check the caller-id permission |
| 3964 | * @hide |
| 3965 | */ |
| 3966 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 3967 | if (mService != null) { |
| 3968 | try { |
| 3969 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 3970 | .getIdentifier()); |
| 3971 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3972 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3973 | } |
| 3974 | } |
| 3975 | return true; |
| 3976 | } |
| 3977 | |
| 3978 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3979 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 3980 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 3981 | * Only activity intents are supported. |
| 3982 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3983 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3984 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 3985 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 3986 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 3987 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3988 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3989 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3990 | if (mService != null) { |
| 3991 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3992 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3993 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3994 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3995 | } |
| 3996 | } |
| 3997 | } |
| 3998 | |
| 3999 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4000 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4001 | * 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] | 4002 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4003 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4004 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4005 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4006 | if (mService != null) { |
| 4007 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4008 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4009 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4010 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4016 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 4017 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4018 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 4019 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4020 | * By default the user can use any accessiblity service. When zero or more packages have |
| 4021 | * been added, accessiblity services that are not in the list and not part of the system |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 4022 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4023 | * |
| 4024 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 4025 | * can be used, calling with an empty list only allows the builtin system's services. |
| 4026 | * |
| 4027 | * <p> System accesibility services are always available to the user the list can't modify |
| 4028 | * this. |
| 4029 | * |
| 4030 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4031 | * @param packageNames List of accessibility service package names. |
| 4032 | * |
| 4033 | * @return true if setting the restriction succeeded. It fail if there is |
| 4034 | * one or more non-system accessibility services enabled, that are not in the list. |
| 4035 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4036 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4037 | List<String> packageNames) { |
| 4038 | if (mService != null) { |
| 4039 | try { |
| 4040 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4041 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4042 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4043 | } |
| 4044 | } |
| 4045 | return false; |
| 4046 | } |
| 4047 | |
| 4048 | /** |
| 4049 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 4050 | * |
| 4051 | * <p>An empty list means no accessibility services except system services are allowed. |
| 4052 | * Null means all accessibility services are allowed. |
| 4053 | * |
| 4054 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4055 | * @return List of accessiblity service package names. |
| 4056 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4057 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4058 | if (mService != null) { |
| 4059 | try { |
| 4060 | return mService.getPermittedAccessibilityServices(admin); |
| 4061 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4062 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | return null; |
| 4066 | } |
| 4067 | |
| 4068 | /** |
| 4069 | * Returns the list of accessibility services permitted by the device or profiles |
| 4070 | * owners of this user. |
| 4071 | * |
| 4072 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4073 | * it will contain the intersection of the permitted lists for any device or profile |
| 4074 | * owners that apply to this user. It will also include any system accessibility services. |
| 4075 | * |
| 4076 | * @param userId which user to check for. |
| 4077 | * @return List of accessiblity service package names. |
| 4078 | * @hide |
| 4079 | */ |
| 4080 | @SystemApi |
| 4081 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4082 | if (mService != null) { |
| 4083 | try { |
| 4084 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4085 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4086 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | return null; |
| 4090 | } |
| 4091 | |
| 4092 | /** |
| 4093 | * Called by a profile or device owner to set the permitted input methods services. When |
| 4094 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4095 | * user the device owner or profile owner is an admin for. |
| 4096 | * |
| 4097 | * By default the user can use any input method. When zero or more packages have |
| 4098 | * been added, input method that are not in the list and not part of the system |
| 4099 | * can not be enabled by the user. |
| 4100 | * |
| 4101 | * This method will fail if it is called for a admin that is not for the foreground user |
| 4102 | * or a profile of the foreground user. |
| 4103 | * |
| 4104 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 4105 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 4106 | * |
| 4107 | * <p> System input methods are always available to the user this method can't modify this. |
| 4108 | * |
| 4109 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4110 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 4111 | * @return true if setting the restriction succeeded. It will fail if there are |
| 4112 | * one or more non-system input methods currently enabled that are not in |
| 4113 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4114 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4115 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4116 | if (mService != null) { |
| 4117 | try { |
| 4118 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4119 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4120 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | return false; |
| 4124 | } |
| 4125 | |
| 4126 | |
| 4127 | /** |
| 4128 | * Returns the list of permitted input methods set by this device or profile owner. |
| 4129 | * |
| 4130 | * <p>An empty list means no input methods except system input methods are allowed. |
| 4131 | * Null means all input methods are allowed. |
| 4132 | * |
| 4133 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4134 | * @return List of input method package names. |
| 4135 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4136 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4137 | if (mService != null) { |
| 4138 | try { |
| 4139 | return mService.getPermittedInputMethods(admin); |
| 4140 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4141 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | return null; |
| 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4149 | * 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] | 4150 | * |
| 4151 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4152 | * it will contain the intersection of the permitted lists for any device or profile |
| 4153 | * owners that apply to this user. It will also include any system input methods. |
| 4154 | * |
| 4155 | * @return List of input method package names. |
| 4156 | * @hide |
| 4157 | */ |
| 4158 | @SystemApi |
| 4159 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4160 | if (mService != null) { |
| 4161 | try { |
| 4162 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4163 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4164 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | return null; |
| 4168 | } |
| 4169 | |
| 4170 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4171 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4172 | * currently installed it. |
| 4173 | * |
| 4174 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4175 | * |
| 4176 | * @return List of package names to keep cached. |
| 4177 | * @hide |
| 4178 | */ |
| 4179 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4180 | if (mService != null) { |
| 4181 | try { |
| 4182 | return mService.getKeepUninstalledPackages(admin); |
| 4183 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4184 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4185 | } |
| 4186 | } |
| 4187 | return null; |
| 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4192 | * currently installed it. |
| 4193 | * |
| 4194 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4195 | * automatically pre-cached.</p> |
| 4196 | * |
| 4197 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4198 | * @param packageNames List of package names to keep cached. |
| 4199 | * @hide |
| 4200 | */ |
| 4201 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4202 | @NonNull List<String> packageNames) { |
| 4203 | if (mService != null) { |
| 4204 | try { |
| 4205 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4206 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4207 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4208 | } |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4213 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4214 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4215 | * created. If you need to persist an identifier for this user, use |
| 4216 | * {@link UserManager#getSerialNumberForUser}. |
| 4217 | * |
| 4218 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4219 | * @param name the user's name |
| 4220 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4221 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4222 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4223 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4224 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4225 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4226 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4227 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4228 | try { |
| 4229 | return mService.createUser(admin, name); |
| 4230 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4231 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4232 | } |
| 4233 | return null; |
| 4234 | } |
| 4235 | |
| 4236 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4237 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4238 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4239 | * created. If you need to persist an identifier for this user, use |
| 4240 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4241 | * immediately. |
| 4242 | * |
| 4243 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4244 | * as registered as an active admin on the new user. The profile owner package will be |
| 4245 | * installed on the new user if it already is installed on the device. |
| 4246 | * |
| 4247 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4248 | * profileOwnerComponent when onEnable is called. |
| 4249 | * |
| 4250 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4251 | * @param name the user's name |
| 4252 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4253 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4254 | * the user. |
| 4255 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4256 | * on the new user. |
| 4257 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4258 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4259 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4260 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4261 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4262 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4263 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4264 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4265 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4266 | try { |
| 4267 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 4268 | adminExtras); |
| 4269 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4270 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4271 | } |
| 4272 | return null; |
| 4273 | } |
| 4274 | |
| 4275 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4276 | * 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] | 4277 | */ |
| 4278 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4279 | |
| 4280 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4281 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4282 | * ephemeral. |
| 4283 | * @hide |
| 4284 | */ |
| 4285 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4286 | |
| 4287 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4288 | * Called by a device owner to create a user with the specified name and a given component of |
| 4289 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4290 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4291 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4292 | * user will not be started in the background. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4293 | * |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4294 | * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also |
| 4295 | * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and |
| 4296 | * will be registered as an active admin on the new user. The profile owner package will be |
| 4297 | * installed on the new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4298 | * |
| 4299 | * <p>If the adminExtras are not null, they will be stored on the device until the user is |
| 4300 | * started for the first time. Then the extras will be passed to the admin when |
| 4301 | * onEnable is called. |
| 4302 | * |
| 4303 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4304 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4305 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
| 4306 | * same package as admin, otherwise no user is created and an IllegalArgumentException is |
| 4307 | * thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4308 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
| 4309 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4310 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4311 | * @see UserHandle |
| 4312 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4313 | * user could not be created. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4314 | */ |
| 4315 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4316 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4317 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4318 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4319 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4320 | } catch (RemoteException re) { |
| 4321 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 4322 | } |
| 4323 | return null; |
| 4324 | } |
| 4325 | |
| 4326 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4327 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 4328 | * not be removed. |
| 4329 | * |
| 4330 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4331 | * @param userHandle the user to remove. |
| 4332 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 4333 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4334 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4335 | try { |
| 4336 | return mService.removeUser(admin, userHandle); |
| 4337 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4338 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4339 | return false; |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4344 | * Called by a device owner to switch the specified user to the foreground. |
| 4345 | * |
| 4346 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4347 | * @param userHandle the user to switch to; null will switch to primary. |
| 4348 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 4349 | * |
| 4350 | * @see Intent#ACTION_USER_FOREGROUND |
| 4351 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4352 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4353 | try { |
| 4354 | return mService.switchUser(admin, userHandle); |
| 4355 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4356 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4357 | return false; |
| 4358 | } |
| 4359 | } |
| 4360 | |
| 4361 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4362 | * Retrieves the application restrictions for a given target application running in the calling |
| 4363 | * user. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4364 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4365 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4366 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4367 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4368 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4369 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4370 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4371 | * @param packageName The name of the package to fetch restricted settings of. |
| 4372 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 4373 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 4374 | * if no restrictions have been set. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4375 | * |
| 4376 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4377 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4378 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4379 | if (mService != null) { |
| 4380 | try { |
| 4381 | return mService.getApplicationRestrictions(admin, packageName); |
| 4382 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4383 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | return null; |
| 4387 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4388 | |
| 4389 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4390 | * 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] | 4391 | * <p> |
| 4392 | * The calling device admin must be a profile or device owner; if it is not, |
| 4393 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4394 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4395 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4396 | * with. |
| 4397 | * @param key The key of the restriction. See the constants in |
| 4398 | * {@link android.os.UserManager} for the list of keys. |
| 4399 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4400 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4401 | if (mService != null) { |
| 4402 | try { |
| 4403 | mService.setUserRestriction(admin, key, true); |
| 4404 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4405 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4406 | } |
| 4407 | } |
| 4408 | } |
| 4409 | |
| 4410 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4411 | * 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] | 4412 | * <p> |
| 4413 | * The calling device admin must be a profile or device owner; if it is not, |
| 4414 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4415 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4416 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4417 | * with. |
| 4418 | * @param key The key of the restriction. See the constants in |
| 4419 | * {@link android.os.UserManager} for the list of keys. |
| 4420 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4421 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4422 | if (mService != null) { |
| 4423 | try { |
| 4424 | mService.setUserRestriction(admin, key, false); |
| 4425 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4426 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4430 | |
| 4431 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4432 | * Called by a profile or device owner to get user restrictions set with |
| 4433 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4434 | * <p> |
| 4435 | * The target user may have more restrictions set by the system or other device owner / profile |
| 4436 | * owner. To get all the user restrictions currently set, use |
| 4437 | * {@link UserManager#getUserRestrictions()}. |
| 4438 | * |
| 4439 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4440 | * @throws SecurityException if the {@code admin} is not an active admin. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4441 | */ |
| 4442 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4443 | return getUserRestrictions(admin, myUserId()); |
| 4444 | } |
| 4445 | |
| 4446 | /** @hide per-user version */ |
| 4447 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4448 | Bundle ret = null; |
| 4449 | if (mService != null) { |
| 4450 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4451 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4452 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4453 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | return ret == null ? new Bundle() : ret; |
| 4457 | } |
| 4458 | |
| 4459 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4460 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4461 | * is unavailable for use, but the data and actual package file remain. |
| 4462 | * |
| 4463 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4464 | * @param packageName The name of the package to hide or unhide. |
| 4465 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 4466 | * unhidden. |
| 4467 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4468 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4469 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4470 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4471 | if (mService != null) { |
| 4472 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4473 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4474 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4475 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4476 | } |
| 4477 | } |
| 4478 | return false; |
| 4479 | } |
| 4480 | |
| 4481 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4482 | * 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] | 4483 | * |
| 4484 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4485 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4486 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4487 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4488 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4489 | if (mService != null) { |
| 4490 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4491 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4492 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4493 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4494 | } |
| 4495 | } |
| 4496 | return false; |
| 4497 | } |
| 4498 | |
| 4499 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4500 | * 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] | 4501 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4502 | * |
| 4503 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4504 | * @param packageName The package to be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4505 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4506 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4507 | if (mService != null) { |
| 4508 | try { |
| 4509 | mService.enableSystemApp(admin, packageName); |
| 4510 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4511 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4517 | * Called by profile or device owners to re-enable system apps by intent that were disabled |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4518 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4519 | * |
| 4520 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4521 | * @param intent An intent matching the app(s) to be installed. All apps that resolve for this |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4522 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4523 | * @return int The number of activities that matched the intent and were installed. |
| 4524 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4525 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4526 | if (mService != null) { |
| 4527 | try { |
| 4528 | return mService.enableSystemAppWithIntent(admin, intent); |
| 4529 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4530 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | return 0; |
| 4534 | } |
| 4535 | |
| 4536 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4537 | * Called by a device owner or profile owner to disable account management for a specific type |
| 4538 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4539 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4540 | * <p>The calling device admin must be a device owner or profile owner. If it is not, a |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4541 | * security exception will be thrown. |
| 4542 | * |
| 4543 | * <p>When account management is disabled for an account type, adding or removing an account |
| 4544 | * of that type will not be possible. |
| 4545 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 4546 | * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
| 4547 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 4548 | * management for a specific type is disabled. |
| 4549 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4550 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4551 | * @param accountType For which account management is disabled or enabled. |
| 4552 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 4553 | * enabled (false). |
| 4554 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4555 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4556 | boolean disabled) { |
| 4557 | if (mService != null) { |
| 4558 | try { |
| 4559 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 4560 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4561 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | } |
| 4565 | |
| 4566 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4567 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 4568 | * |
| 4569 | * <p> Account management can be disabled/enabled by calling |
| 4570 | * {@link #setAccountManagementDisabled}. |
| 4571 | * |
| 4572 | * @return a list of account types for which account management has been disabled. |
| 4573 | * |
| 4574 | * @see #setAccountManagementDisabled |
| 4575 | */ |
| 4576 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4577 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | /** |
| 4581 | * @see #getAccountTypesWithManagementDisabled() |
| 4582 | * @hide |
| 4583 | */ |
| 4584 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4585 | if (mService != null) { |
| 4586 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4587 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4588 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4589 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | |
| 4593 | return null; |
| 4594 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4595 | |
| 4596 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4597 | * Sets which packages may enter lock task mode. |
| 4598 | * |
| 4599 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 4600 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4601 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4602 | * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 4603 | * package list results in locked tasks belonging to those packages to be finished. |
| 4604 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 4605 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4606 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4607 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4608 | * |
| 4609 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 4610 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 4611 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 4612 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4613 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4614 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4615 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4616 | if (mService != null) { |
| 4617 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4618 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4619 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4620 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4626 | * 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] | 4627 | * |
| 4628 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4629 | * @hide |
| 4630 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4631 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4632 | if (mService != null) { |
| 4633 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4634 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4635 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4636 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | return null; |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * This function lets the caller know whether the given component is allowed to start the |
| 4644 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4645 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4646 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4647 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4648 | if (mService != null) { |
| 4649 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4650 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4651 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4652 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4653 | } |
| 4654 | } |
| 4655 | return false; |
| 4656 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4657 | |
| 4658 | /** |
| 4659 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 4660 | * of the setting is in the correct form for the setting type should be performed by the caller. |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4661 | * <p>The settings that can be updated with this method are: |
| 4662 | * <ul> |
| 4663 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 4664 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 4665 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4666 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4667 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4668 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 4669 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4670 | * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4671 | * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
Zoltan Szatmary-Ban | 4045d24 | 2015-05-27 12:42:39 +0100 | [diff] [blame] | 4672 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4673 | * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards. |
Zoltan Szatmary-Ban | 3c43095 | 2015-07-03 14:04:09 +0100 | [diff] [blame] | 4674 | * </li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4675 | * </ul> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4676 | * <p>Changing the following settings has no effect as of |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4677 | * {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4678 | * <ul> |
| 4679 | * <li>{@link Settings.Global#BLUETOOTH_ON}. |
| 4680 | * Use {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 4681 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
| 4682 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 4683 | * <li>{@link Settings.Global#MODE_RINGER}. |
| 4684 | * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
| 4685 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 4686 | * <li>{@link Settings.Global#WIFI_ON}. |
| 4687 | * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
| 4688 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4689 | * |
| 4690 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4691 | * @param setting The name of the setting to update. |
| 4692 | * @param value The value to update the setting to. |
| 4693 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4694 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4695 | if (mService != null) { |
| 4696 | try { |
| 4697 | mService.setGlobalSetting(admin, setting, value); |
| 4698 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4699 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | /** |
| 4705 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 4706 | * that the value of the setting is in the correct form for the setting type should be performed |
| 4707 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4708 | * <p>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] | 4709 | * <ul> |
| 4710 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 4711 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4712 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 4713 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4714 | * <p>A device owner can additionally update the following settings: |
| 4715 | * <ul> |
| 4716 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 4717 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4718 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4719 | * @param setting The name of the setting to update. |
| 4720 | * @param value The value to update the setting to. |
| 4721 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4722 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4723 | if (mService != null) { |
| 4724 | try { |
| 4725 | mService.setSecureSetting(admin, setting, value); |
| 4726 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4727 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4728 | } |
| 4729 | } |
| 4730 | } |
| 4731 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4732 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4733 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4734 | * making permission requests of a local or remote administrator of the user. |
| 4735 | * <p/> |
| 4736 | * Only a profile owner can designate the restrictions provider. |
| 4737 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4738 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 4739 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4740 | * it removes the restrictions provider previously assigned. |
| 4741 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4742 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 4743 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4744 | if (mService != null) { |
| 4745 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4746 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4747 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4748 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4749 | } |
| 4750 | } |
| 4751 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4752 | |
| 4753 | /** |
| 4754 | * Called by profile or device owners to set the master volume mute on or off. |
| 4755 | * |
| 4756 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4757 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 4758 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4759 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4760 | if (mService != null) { |
| 4761 | try { |
| 4762 | mService.setMasterVolumeMuted(admin, on); |
| 4763 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4764 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4765 | } |
| 4766 | } |
| 4767 | } |
| 4768 | |
| 4769 | /** |
| 4770 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 4771 | * |
| 4772 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4773 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 4774 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4775 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4776 | if (mService != null) { |
| 4777 | try { |
| 4778 | return mService.isMasterVolumeMuted(admin); |
| 4779 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4780 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4781 | } |
| 4782 | } |
| 4783 | return false; |
| 4784 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4785 | |
| 4786 | /** |
| 4787 | * Called by profile or device owners to change whether a user can uninstall |
| 4788 | * a package. |
| 4789 | * |
| 4790 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4791 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4792 | * @param uninstallBlocked true if the user shouldn't be able to uninstall the package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4793 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4794 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4795 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4796 | if (mService != null) { |
| 4797 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4798 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4799 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4800 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4801 | } |
| 4802 | } |
| 4803 | } |
| 4804 | |
| 4805 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4806 | * 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] | 4807 | * 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] | 4808 | * <p> |
| 4809 | * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4810 | * behavior of this API is changed such that passing {@code null} as the {@code admin} |
Rubin Xu | e1e6faa | 2015-03-10 10:51:59 +0000 | [diff] [blame] | 4811 | * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4812 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4813 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4814 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 4815 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4816 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 4817 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4818 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4819 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4820 | if (mService != null) { |
| 4821 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 4822 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4823 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4824 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | return false; |
| 4828 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4829 | |
| 4830 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4831 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 4832 | * given package to be available in the parent profile. As a result the user will be able to |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4833 | * add widgets from the white-listed package running under the profile to a widget |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4834 | * host which runs under the parent profile, for example the home screen. Note that |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4835 | * a package may have zero or more provider components, where each component |
| 4836 | * provides a different widget type. |
| 4837 | * <p> |
| 4838 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4839 | * |
| 4840 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4841 | * @param packageName The package from which widget providers are white-listed. |
| 4842 | * @return Whether the package was added. |
| 4843 | * |
| 4844 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4845 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4846 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4847 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4848 | if (mService != null) { |
| 4849 | try { |
| 4850 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 4851 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4852 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4853 | } |
| 4854 | } |
| 4855 | return false; |
| 4856 | } |
| 4857 | |
| 4858 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4859 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 4860 | * package to be available in the parent profile. For this method to take effect the |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4861 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 4862 | * android.content.ComponentName, String)}. |
| 4863 | * <p> |
| 4864 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4865 | * |
| 4866 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4867 | * @param packageName The package from which widget providers are no longer |
| 4868 | * white-listed. |
| 4869 | * @return Whether the package was removed. |
| 4870 | * |
| 4871 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4872 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4873 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4874 | public boolean removeCrossProfileWidgetProvider( |
| 4875 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4876 | if (mService != null) { |
| 4877 | try { |
| 4878 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 4879 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4880 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4881 | } |
| 4882 | } |
| 4883 | return false; |
| 4884 | } |
| 4885 | |
| 4886 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4887 | * 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] | 4888 | * available in the parent profile. |
| 4889 | * |
| 4890 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4891 | * @return The white-listed package list. |
| 4892 | * |
| 4893 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4894 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4895 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4896 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4897 | if (mService != null) { |
| 4898 | try { |
| 4899 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 4900 | if (providers != null) { |
| 4901 | return providers; |
| 4902 | } |
| 4903 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4904 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | return Collections.emptyList(); |
| 4908 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4909 | |
| 4910 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4911 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4912 | * |
| 4913 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4914 | * @param icon the bitmap to set as the photo. |
| 4915 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4916 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4917 | try { |
| 4918 | mService.setUserIcon(admin, icon); |
| 4919 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4920 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4921 | } |
| 4922 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 4923 | |
| 4924 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4925 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 4926 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4927 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4928 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 4929 | * components in the device owner package can set system update policies and the |
| 4930 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4931 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4932 | * @param policy the new policy, or {@code null} to clear the current policy. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4933 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4934 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4935 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4936 | if (mService != null) { |
| 4937 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4938 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4939 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4940 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4941 | } |
| 4942 | } |
| 4943 | } |
| 4944 | |
| 4945 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4946 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4947 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4948 | * @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] | 4949 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4950 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4951 | if (mService != null) { |
| 4952 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 4953 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4954 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4955 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | return null; |
| 4959 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4960 | |
| 4961 | /** |
| 4962 | * Called by a device owner to disable the keyguard altogether. |
| 4963 | * |
| 4964 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 4965 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 4966 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 4967 | * being disabled. |
| 4968 | * |
| 4969 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4970 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4971 | * |
| 4972 | * @return {@code false} if attempting to disable the keyguard while a lock password was in |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4973 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4974 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4975 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4976 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4977 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4978 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4979 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4980 | return false; |
| 4981 | } |
| 4982 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4983 | |
| 4984 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4985 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 4986 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4987 | * a single use device. |
| 4988 | * |
| 4989 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4990 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 4991 | * |
| 4992 | * @return {@code false} if attempting to disable the status bar failed. |
| 4993 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4994 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4995 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4996 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4997 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4998 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4999 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5000 | return false; |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5001 | } |
| 5002 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5003 | |
| 5004 | /** |
| 5005 | * Callable by the system update service to notify device owners about pending updates. |
| 5006 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5007 | * permission. |
| 5008 | * |
| 5009 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5010 | * when the current pending update was first available. -1 if no update is available. |
| 5011 | * @hide |
| 5012 | */ |
| 5013 | @SystemApi |
| 5014 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5015 | if (mService != null) { |
| 5016 | try { |
| 5017 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5018 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5019 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5023 | |
| 5024 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5025 | * Called by profile or device owners to set the default response for future runtime permission |
| 5026 | * requests by applications. The policy can allow for normal operation which prompts the |
| 5027 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 5028 | * permission requests by an application. This also applies to new permissions declared by app |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5029 | * updates. When a permission is denied or granted this way, the effect is equivalent to setting |
| 5030 | * the permission grant state via {@link #setPermissionGrantState}. |
| 5031 | * |
| 5032 | * <p/>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] | 5033 | * 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] | 5034 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5035 | * @param admin Which profile or device owner this request is associated with. |
| 5036 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 5037 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5038 | * |
| 5039 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5040 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5041 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5042 | try { |
| 5043 | mService.setPermissionPolicy(admin, policy); |
| 5044 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5045 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5046 | } |
| 5047 | } |
| 5048 | |
| 5049 | /** |
| 5050 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5051 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5052 | * @param admin Which profile or device owner this request is associated with. |
| 5053 | * @return the current policy for future permission requests. |
| 5054 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5055 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5056 | try { |
| 5057 | return mService.getPermissionPolicy(admin); |
| 5058 | } catch (RemoteException re) { |
| 5059 | return PERMISSION_POLICY_PROMPT; |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5064 | * Sets the grant state of a runtime permission for a specific application. The state |
| 5065 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 5066 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 5067 | * is denied and the user cannot manage it through the UI, and {@link |
| 5068 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 5069 | * user cannot manage it through the UI. This might affect all permissions in a |
| 5070 | * group that the runtime permission belongs to. This method can only be called |
| 5071 | * by a profile or device owner. |
| 5072 | * |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5073 | * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not |
| 5074 | * revoke the permission. It retains the previous grant, if any. |
| 5075 | * |
| 5076 | * <p/>Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5077 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5078 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5079 | * @param admin Which profile or device owner this request is associated with. |
| 5080 | * @param packageName The application to grant or revoke a permission to. |
| 5081 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5082 | * @param grantState The permission grant state which is one of {@link |
| 5083 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5084 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5085 | * @return whether the permission was successfully granted or revoked. |
| 5086 | * |
| 5087 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5088 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5089 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5090 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5091 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5092 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5093 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5094 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5095 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5096 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5097 | return false; |
| 5098 | } |
| 5099 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5100 | |
| 5101 | /** |
| 5102 | * Returns the current grant state of a runtime permission for a specific application. |
| 5103 | * |
| 5104 | * @param admin Which profile or device owner this request is associated with. |
| 5105 | * @param packageName The application to check the grant state for. |
| 5106 | * @param permission The permission to check for. |
| 5107 | * @return the current grant state specified by device policy. If the profile or device owner |
| 5108 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 5109 | * This does not indicate whether or not the permission is currently granted for the package. |
| 5110 | * |
| 5111 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 5112 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5113 | * which indicates if the permission is currently denied or granted. |
| 5114 | * |
| 5115 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5116 | * @see PackageManager#checkPermission(String, String) |
| 5117 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5118 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5119 | String permission) { |
| 5120 | try { |
| 5121 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5122 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5123 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5124 | return PERMISSION_GRANT_STATE_DEFAULT; |
| 5125 | } |
| 5126 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5127 | |
| 5128 | /** |
| 5129 | * Returns if provisioning a managed profile or device is possible or not. |
| 5130 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5131 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 5132 | * Note that even if this method returns true, there is a slight possibility that the |
| 5133 | * provisioning will not be allowed when it is actually initiated because some event has |
| 5134 | * happened in between. |
| 5135 | * @return if provisioning a managed profile or device is possible or not. |
| 5136 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5137 | */ |
| 5138 | public boolean isProvisioningAllowed(String action) { |
| 5139 | try { |
| 5140 | return mService.isProvisioningAllowed(action); |
| 5141 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5142 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5143 | return false; |
| 5144 | } |
| 5145 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5146 | |
| 5147 | /** |
| 5148 | * @hide |
| 5149 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5150 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5151 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5152 | * @param admin Which profile owner this request is associated with. |
| 5153 | * @return if this user is a managed profile of another user. |
| 5154 | */ |
| 5155 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5156 | try { |
| 5157 | return mService.isManagedProfile(admin); |
| 5158 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5159 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5160 | return false; |
| 5161 | } |
| 5162 | } |
| 5163 | |
| 5164 | /** |
| 5165 | * @hide |
| 5166 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5167 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5168 | * @param admin Which device owner this request is associated with. |
| 5169 | * @return if this user is a system-only user. |
| 5170 | */ |
| 5171 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5172 | try { |
| 5173 | return mService.isSystemOnlyUser(admin); |
| 5174 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5175 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5176 | return false; |
| 5177 | } |
| 5178 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5179 | |
| 5180 | /** |
| 5181 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5182 | * |
| 5183 | * @return the MAC address of the Wi-Fi device, or null when the information is not |
| 5184 | * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5185 | * |
| 5186 | * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5187 | */ |
| 5188 | public String getWifiMacAddress() { |
| 5189 | try { |
| 5190 | return mService.getWifiMacAddress(); |
| 5191 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5192 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5193 | return null; |
| 5194 | } |
| 5195 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5196 | |
| 5197 | /** |
| 5198 | * Called by device owner to reboot the device. |
| 5199 | */ |
| 5200 | public void reboot(@NonNull ComponentName admin) { |
| 5201 | try { |
| 5202 | mService.reboot(admin); |
| 5203 | } catch (RemoteException re) { |
| 5204 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5205 | } |
| 5206 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5207 | |
| 5208 | /** |
| 5209 | * Called by a device admin to set the short support message. This will |
| 5210 | * be displayed to the user in settings screens where funtionality has |
| 5211 | * been disabled by the admin. |
| 5212 | * |
| 5213 | * The message should be limited to a short statement such as |
| 5214 | * "This setting is disabled by your administrator. Contact someone@example.com |
| 5215 | * for support." |
| 5216 | * If the message is longer than 200 characters it may be truncated. |
| 5217 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame^] | 5218 | * <p>If the short support message needs to be localized, it is the responsibility of the |
| 5219 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5220 | * and set a new version of this string accordingly. |
| 5221 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5222 | * @see #setLongSupportMessage |
| 5223 | * |
| 5224 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5225 | * @param message Short message to be displayed to the user in settings or null to |
| 5226 | * clear the existing message. |
| 5227 | */ |
| 5228 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5229 | @Nullable String message) { |
| 5230 | if (mService != null) { |
| 5231 | try { |
| 5232 | mService.setShortSupportMessage(admin, message); |
| 5233 | } catch (RemoteException e) { |
| 5234 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5235 | } |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | /** |
| 5240 | * Called by a device admin to get the short support message. |
| 5241 | * |
| 5242 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5243 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5244 | * or null if no message has been set. |
| 5245 | */ |
| 5246 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5247 | if (mService != null) { |
| 5248 | try { |
| 5249 | return mService.getShortSupportMessage(admin); |
| 5250 | } catch (RemoteException e) { |
| 5251 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5252 | } |
| 5253 | } |
| 5254 | return null; |
| 5255 | } |
| 5256 | |
| 5257 | /** |
| 5258 | * Called by a device admin to set the long support message. This will |
| 5259 | * be displayed to the user in the device administators settings screen. |
| 5260 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame^] | 5261 | * <p>If the long support message needs to be localized, it is the responsibility of the |
| 5262 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5263 | * and set a new version of this string accordingly. |
| 5264 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5265 | * @see #setShortSupportMessage |
| 5266 | * |
| 5267 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5268 | * @param message Long message to be displayed to the user in settings or null to |
| 5269 | * clear the existing message. |
| 5270 | */ |
| 5271 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5272 | @Nullable String message) { |
| 5273 | if (mService != null) { |
| 5274 | try { |
| 5275 | mService.setLongSupportMessage(admin, message); |
| 5276 | } catch (RemoteException e) { |
| 5277 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5278 | } |
| 5279 | } |
| 5280 | } |
| 5281 | |
| 5282 | /** |
| 5283 | * Called by a device admin to get the long support message. |
| 5284 | * |
| 5285 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5286 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5287 | * or null if no message has been set. |
| 5288 | */ |
| 5289 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5290 | if (mService != null) { |
| 5291 | try { |
| 5292 | return mService.getLongSupportMessage(admin); |
| 5293 | } catch (RemoteException e) { |
| 5294 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5295 | } |
| 5296 | } |
| 5297 | return null; |
| 5298 | } |
| 5299 | |
| 5300 | /** |
| 5301 | * Called by the system to get the short support message. |
| 5302 | * |
| 5303 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5304 | * @param userHandle user id the admin is running as. |
| 5305 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5306 | * |
| 5307 | * @hide |
| 5308 | */ |
| 5309 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5310 | if (mService != null) { |
| 5311 | try { |
| 5312 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5313 | } catch (RemoteException e) { |
| 5314 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5315 | } |
| 5316 | } |
| 5317 | return null; |
| 5318 | } |
| 5319 | |
| 5320 | |
| 5321 | /** |
| 5322 | * Called by the system to get the long support message. |
| 5323 | * |
| 5324 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5325 | * @param userHandle user id the admin is running as. |
| 5326 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5327 | * |
| 5328 | * @hide |
| 5329 | */ |
| 5330 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5331 | if (mService != null) { |
| 5332 | try { |
| 5333 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5334 | } catch (RemoteException e) { |
| 5335 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5336 | } |
| 5337 | } |
| 5338 | return null; |
| 5339 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5340 | |
| 5341 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5342 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5343 | * whose calls act on the parent profile. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5344 | * |
| 5345 | * <p> Note only some methods will work on the parent Manager. |
| 5346 | * |
| 5347 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
| 5348 | */ |
| 5349 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5350 | try { |
| 5351 | if (!mService.isManagedProfile(admin)) { |
| 5352 | throw new SecurityException("The current user does not have a parent profile."); |
| 5353 | } |
| 5354 | return new DevicePolicyManager(mContext, true); |
| 5355 | } catch (RemoteException re) { |
| 5356 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5357 | return null; |
| 5358 | } |
| 5359 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5360 | |
| 5361 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 5362 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 5363 | * profile. |
| 5364 | * |
| 5365 | * @hide |
| 5366 | */ |
| 5367 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 5368 | mContext.checkSelfPermission( |
| 5369 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 5370 | if (!uInfo.isManagedProfile()) { |
| 5371 | throw new SecurityException("The user " + uInfo.id |
| 5372 | + " does not have a parent profile."); |
| 5373 | } |
| 5374 | return new DevicePolicyManager(mContext, true); |
| 5375 | } |
| 5376 | |
| 5377 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5378 | * Called by a profile owner of a managed profile to set the color used for customization. |
| 5379 | * This color is used as background color of the confirm credentials screen for that user. |
| 5380 | * The default color is {@link android.graphics.Color#GRAY}. |
| 5381 | * |
| 5382 | * <p>The confirm credentials screen can be created using |
| 5383 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5384 | * |
| 5385 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5386 | * @param color The 32bit representation of the color to be used. |
| 5387 | */ |
| 5388 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5389 | try { |
| 5390 | mService.setOrganizationColor(admin, color); |
| 5391 | } catch (RemoteException re) { |
| 5392 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5393 | } |
| 5394 | } |
| 5395 | |
| 5396 | /** |
| 5397 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5398 | * This color is used as background color of the confirm credentials screen for that user. |
| 5399 | * |
| 5400 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5401 | * @return The 32bit representation of the color to be used. |
| 5402 | */ |
| 5403 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 5404 | try { |
| 5405 | return mService.getOrganizationColor(admin); |
| 5406 | } catch (RemoteException re) { |
| 5407 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5408 | return 0; |
| 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * @hide |
| 5414 | * Retrieve the customization color for a given user. |
| 5415 | * |
| 5416 | * @param userHandle The user id of the user we're interested in. |
| 5417 | * @return The 32bit representation of the color to be used. |
| 5418 | */ |
| 5419 | public int getOrganizationColorForUser(int userHandle) { |
| 5420 | try { |
| 5421 | return mService.getOrganizationColorForUser(userHandle); |
| 5422 | } catch (RemoteException re) { |
| 5423 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5424 | return 0; |
| 5425 | } |
| 5426 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5427 | |
| 5428 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame^] | 5429 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 5430 | * management. |
| 5431 | * |
| 5432 | * <p>If the organization name needs to be localized, it is the responsibility of the |
| 5433 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5434 | * and set a new version of this string accordingly. |
| 5435 | * |
| 5436 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5437 | * @param title The organization name or {@code null} to clear a previously set name. |
| 5438 | */ |
| 5439 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 5440 | try { |
| 5441 | mService.setOrganizationName(admin, title); |
| 5442 | } catch (RemoteException re) { |
| 5443 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | /** |
| 5448 | * Called by a profile owner of a managed profile to retrieve the name of the organization |
| 5449 | * under management. |
| 5450 | * |
| 5451 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5452 | * @return The organization name or {@code null} if none is set. |
| 5453 | */ |
| 5454 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 5455 | try { |
| 5456 | return mService.getOrganizationName(admin); |
| 5457 | } catch (RemoteException re) { |
| 5458 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5459 | return null; |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | /** |
| 5464 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 5465 | * |
| 5466 | * @param userHandle The user id of the user we're interested in. |
| 5467 | * @return The organization name or {@code null} if none is set. |
| 5468 | * |
| 5469 | * @hide |
| 5470 | */ |
| 5471 | public String getOrganizationNameForUser(int userHandle) { |
| 5472 | try { |
| 5473 | return mService.getOrganizationNameForUser(userHandle); |
| 5474 | } catch (RemoteException re) { |
| 5475 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5476 | return null; |
| 5477 | } |
| 5478 | } |
| 5479 | |
| 5480 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5481 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 5482 | * return {@link #STATE_USER_UNMANAGED} |
| 5483 | * @hide |
| 5484 | */ |
| 5485 | @UserProvisioningState |
| 5486 | public int getUserProvisioningState() { |
| 5487 | if (mService != null) { |
| 5488 | try { |
| 5489 | return mService.getUserProvisioningState(); |
| 5490 | } catch (RemoteException e) { |
| 5491 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5492 | } |
| 5493 | } |
| 5494 | return STATE_USER_UNMANAGED; |
| 5495 | } |
| 5496 | |
| 5497 | /** |
| 5498 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 5499 | * |
| 5500 | * @param state to store |
| 5501 | * @param userHandle for user |
| 5502 | * @hide |
| 5503 | */ |
| 5504 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 5505 | if (mService != null) { |
| 5506 | try { |
| 5507 | mService.setUserProvisioningState(state, userHandle); |
| 5508 | } catch (RemoteException e) { |
| 5509 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5510 | } |
| 5511 | } |
| 5512 | } |
| 5513 | |
| 5514 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5515 | * @hide |
| 5516 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 5517 | * affiliated if it is managed by the same entity as the device. |
| 5518 | * |
| 5519 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 5520 | * user/profile is considered affiliated if the following conditions are both met: |
| 5521 | * <ul> |
| 5522 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 5523 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 5524 | * and a profile owner intersect, they must have come from the same source, which means that |
| 5525 | * the device owner and profile owner are controlled by the same entity.</li> |
| 5526 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 5527 | * </ul> |
| 5528 | * |
| 5529 | * @param admin Which profile or device owner this request is associated with. |
| 5530 | * @param ids A set of opaque affiliation ids. |
| 5531 | */ |
| 5532 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 5533 | try { |
| 5534 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 5535 | } catch (RemoteException e) { |
| 5536 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5537 | } |
| 5538 | } |
| 5539 | |
| 5540 | /** |
| 5541 | * @hide |
| 5542 | * Returns whether this user/profile is affiliated with the device. See |
| 5543 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 5544 | * |
| 5545 | * @return whether this user/profile is affiliated with the device. |
| 5546 | */ |
| 5547 | public boolean isAffiliatedUser() { |
| 5548 | try { |
| 5549 | return mService != null && mService.isAffiliatedUser(); |
| 5550 | } catch (RemoteException e) { |
| 5551 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5552 | return false; |
| 5553 | } |
| 5554 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5555 | } |