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; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 33 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 34 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 35 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 36 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 37 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 38 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 39 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 40 | import android.os.RemoteException; |
| 41 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 42 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 43 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 44 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 45 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 46 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 47 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 48 | import android.util.Log; |
| 49 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 50 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 51 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 52 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 53 | import org.xmlpull.v1.XmlPullParserException; |
| 54 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 55 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 56 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 57 | import java.lang.annotation.Retention; |
| 58 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 59 | import java.net.InetSocketAddress; |
| 60 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 61 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 62 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 63 | import java.security.PrivateKey; |
| 64 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 65 | import java.security.cert.CertificateException; |
| 66 | import java.security.cert.CertificateFactory; |
| 67 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 68 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 69 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 70 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 71 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 72 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 73 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 76 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 77 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 78 | * <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] | 79 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 80 | * accessible to all device administrators unless the documentation for that method specifies that |
| 81 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 82 | * |
| 83 | * <div class="special reference"> |
| 84 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 85 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 86 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 87 | * developer guide. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 88 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 89 | */ |
| 90 | public class DevicePolicyManager { |
| 91 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 92 | |
| 93 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 94 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 95 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 96 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 97 | private static final String REMOTE_EXCEPTION_MESSAGE = |
| 98 | "Failed to talk with device policy manager service"; |
| 99 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 100 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 101 | this(context, |
| 102 | IDevicePolicyManager.Stub.asInterface( |
| 103 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 104 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 107 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 108 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 109 | protected DevicePolicyManager( |
| 110 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 111 | mContext = context; |
| 112 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 113 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** @hide */ |
| 117 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 118 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 119 | return me.mService != null ? me : null; |
| 120 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 121 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 122 | /** @hide test will override it. */ |
| 123 | @VisibleForTesting |
| 124 | protected int myUserId() { |
| 125 | return UserHandle.myUserId(); |
| 126 | } |
| 127 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 128 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 129 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 130 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 131 | * <p>A managed profile allows data separation for example for the usage of a |
| 132 | * device as a personal and corporate device. The user which provisioning is started from and |
| 133 | * the managed profile share a launcher. |
| 134 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 135 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 136 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 137 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 138 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 139 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 140 | * {@link #isProvisioningAllowed(String)}. |
| 141 | * |
| 142 | * <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] | 143 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 144 | * 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] | 145 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 146 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 147 | * |
| 148 | * <p> The intent may also contain the following extras: |
| 149 | * <ul> |
| 150 | * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li> |
| 151 | * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li> |
| 152 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 153 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 154 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 155 | * in the provisioning intent. The |
| 156 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 157 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 158 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 159 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 160 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 161 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 162 | * |
| 163 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 164 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 165 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 166 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 167 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 168 | */ |
| 169 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 170 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 171 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 172 | |
| 173 | /** |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 174 | * @hide |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 175 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 176 | * |
| 177 | * <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] | 178 | * 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] | 179 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 180 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 181 | * allowed. |
| 182 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 183 | * <p>This intent should contain the extra |
| 184 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 185 | * |
| 186 | * <p> If provisioning fails, the device returns to its previous state. |
| 187 | * |
| 188 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 189 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 190 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 191 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 192 | * 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] | 193 | */ |
| 194 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 195 | public static final String ACTION_PROVISION_MANAGED_USER |
| 196 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 197 | |
| 198 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 199 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 200 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 201 | * |
| 202 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 203 | * A device owner has full control over the device. The device owner can not be modified by the |
| 204 | * user. |
| 205 | * |
| 206 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 207 | * employee or client. |
| 208 | * |
| 209 | * <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] | 210 | * It is possible to check if provisioning is allowed or not by querying the method |
| 211 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 212 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 213 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 214 | * <ul> |
| 215 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 216 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 217 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 218 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 219 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 220 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 221 | * </ul> |
| 222 | * |
| 223 | * <p> When device owner provisioning has completed, an intent of the type |
| 224 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 225 | * device owner. |
| 226 | * |
| 227 | * <p> If provisioning fails, the device is factory reset. |
| 228 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 229 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 230 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 231 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 232 | * 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] | 233 | */ |
| 234 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 235 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 236 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 237 | |
| 238 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 239 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 240 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 241 | * |
| 242 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 243 | * management state that is distinct from that reached by |
| 244 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 245 | * user, and only has control over device-wide policies, not individual users and their data. |
| 246 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 247 | * this form of device management. |
| 248 | * |
| 249 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 250 | * A device owner has full control over the device. The device owner can not be modified by the |
| 251 | * user. |
| 252 | * |
| 253 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 254 | * employee or client. |
| 255 | * |
| 256 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 257 | * It is possible to check if provisioning is allowed or not by querying the method |
| 258 | * {@link #isProvisioningAllowed(String)}. |
| 259 | * |
| 260 | * <p>The intent contains the following extras: |
| 261 | * <ul> |
| 262 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 266 | * </ul> |
| 267 | * |
| 268 | * <p> When device owner provisioning has completed, an intent of the type |
| 269 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 270 | * device owner. |
| 271 | * |
| 272 | * <p> If provisioning fails, the device is factory reset. |
| 273 | * |
| 274 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 275 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 276 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 277 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 278 | * |
| 279 | * @hide |
| 280 | */ |
| 281 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 282 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 283 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 284 | |
| 285 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 286 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 287 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 288 | * <ul> |
| 289 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 290 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 291 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 292 | * </ul> |
| 293 | * |
| 294 | * @hide |
| 295 | */ |
| 296 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 297 | public static final String ACTION_PROVISION_FINALIZATION |
| 298 | = "android.app.action.PROVISION_FINALIZATION"; |
| 299 | |
| 300 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 301 | * 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] | 302 | * allows a mobile device management application or NFC programmer application which starts |
| 303 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 304 | * <p> |
| 305 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 306 | * sends the intent to pass data to itself on the newly created profile. |
| 307 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 308 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 309 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 310 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 311 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 312 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 313 | * management application after provisioning. |
| 314 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 315 | * <p> |
| 316 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 317 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 318 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 319 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 320 | */ |
| 321 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 322 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 323 | |
| 324 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 325 | * A String extra holding the package name of the mobile device management application that |
| 326 | * will be set as the profile owner or device owner. |
| 327 | * |
| 328 | * <p>If an application starts provisioning directly via an intent with action |
| 329 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 330 | * application that started provisioning. The package will be set as profile owner in that case. |
| 331 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 332 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 333 | * 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] | 334 | * |
| 335 | * <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] | 336 | * 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] | 337 | |
| 338 | * @see DeviceAdminReceiver |
| 339 | * @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] | 340 | * supported, but only if there is only one device admin receiver in the package that requires |
| 341 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 342 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 343 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 344 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 345 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 346 | |
| 347 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 348 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 349 | * application that will be set as the profile owner or device owner and active admin. |
| 350 | * |
| 351 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 352 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 353 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 354 | * 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] | 355 | * |
| 356 | * <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] | 357 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 358 | * message containing an NFC record with MIME type |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 359 | * {@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] | 360 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 361 | * |
| 362 | * @see DeviceAdminReceiver |
| 363 | */ |
| 364 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 365 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 366 | |
| 367 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 368 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 369 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 370 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 371 | * |
| 372 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 373 | */ |
| 374 | |
| 375 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 376 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 377 | |
| 378 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 379 | * A String extra that, holds the email address of the account which a managed profile is |
| 380 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 381 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 382 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 383 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 384 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 385 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 386 | * contains this extra, it is forwarded in the |
| 387 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 388 | * device management application that was set as the profile owner during provisioning. |
| 389 | * 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] | 390 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 391 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 392 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 393 | |
| 394 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 395 | * A integer extra indicating the predominant color to show during the provisioning. |
| 396 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 397 | * |
| 398 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 399 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 400 | */ |
| 401 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 402 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 403 | |
| 404 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 405 | * 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] | 406 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 407 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 408 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 409 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 410 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 411 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 412 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 413 | |
| 414 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 415 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 416 | * will be set to. |
| 417 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 418 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 419 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 420 | */ |
| 421 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 422 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 423 | |
| 424 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 425 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 426 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 427 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 428 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 429 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 430 | */ |
| 431 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 432 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 433 | |
| 434 | /** |
| 435 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 436 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 437 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 438 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 439 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 440 | */ |
| 441 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 442 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 443 | |
| 444 | /** |
| 445 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 446 | * owner provisioning for downloading the mobile device management application. |
| 447 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 448 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 449 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 450 | */ |
| 451 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 452 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 453 | |
| 454 | /** |
| 455 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 456 | * is hidden or not. |
| 457 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 458 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 459 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 460 | */ |
| 461 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 462 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 463 | |
| 464 | /** |
| 465 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 466 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 467 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 468 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 469 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 470 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 471 | */ |
| 472 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 473 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 474 | |
| 475 | /** |
| 476 | * A String extra holding the password of the wifi network in |
| 477 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 478 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 479 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 480 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 481 | */ |
| 482 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 483 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 484 | |
| 485 | /** |
| 486 | * A String extra holding the proxy host for the wifi network in |
| 487 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 488 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 489 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 490 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 491 | */ |
| 492 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 493 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 494 | |
| 495 | /** |
| 496 | * An int extra holding the proxy port for the wifi network in |
| 497 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 498 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 499 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 500 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 501 | */ |
| 502 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 503 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 504 | |
| 505 | /** |
| 506 | * A String extra holding the proxy bypass for the wifi network in |
| 507 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 508 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 509 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 510 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 511 | */ |
| 512 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 513 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 514 | |
| 515 | /** |
| 516 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 517 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 518 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 519 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 520 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 521 | */ |
| 522 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 523 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * A String extra holding a url that specifies the download location of the device admin |
| 527 | * package. When not provided it is assumed that the device admin package is already installed. |
| 528 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 529 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 530 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 531 | */ |
| 532 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 533 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 534 | |
| 535 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 536 | * An int extra holding a minimum required version code for the device admin package. If the |
| 537 | * device admin is already installed on the device, it will only be re-downloaded from |
| 538 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 539 | * installed package is less than this version code. |
| 540 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 541 | * <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] | 542 | * provisioning via an NFC bump. |
| 543 | */ |
| 544 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 545 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 546 | |
| 547 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 548 | * A String extra holding a http cookie header which should be used in the http request to the |
| 549 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 550 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 551 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 552 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 553 | */ |
| 554 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 555 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 556 | |
| 557 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 558 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 559 | * the file at download location specified in |
| 560 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 561 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 562 | * <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] | 563 | * present. The provided checksum should match the checksum of the file at the download |
| 564 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 565 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 566 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 567 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 568 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 569 | * |
| 570 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 571 | * 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] | 572 | * 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] | 573 | * 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] | 574 | */ |
| 575 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 576 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 577 | |
| 578 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 579 | * 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] | 580 | * android package archive at the download location specified in {@link |
| 581 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 582 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 583 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 584 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 585 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 586 | * |
| 587 | * <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] | 588 | * 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] | 589 | * the download location. If the checksum does not match an error will be shown to the user and |
| 590 | * the user will be asked to factory reset the device. |
| 591 | * |
| 592 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 593 | * provisioning via an NFC bump. |
| 594 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 595 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 596 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 597 | |
| 598 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 599 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 600 | * has completed successfully. |
| 601 | * |
| 602 | * <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] | 603 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 604 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 605 | * <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] | 606 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 607 | */ |
| 608 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 609 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 610 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 611 | |
| 612 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 613 | * 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] | 614 | * provisioning. |
| 615 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 616 | * <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] | 617 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 618 | */ |
| 619 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 620 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 621 | |
| 622 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 623 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 624 | * provisioning. If this extra is not passed, a default image will be shown. |
| 625 | * <h5>The following URI schemes are accepted:</h5> |
| 626 | * <ul> |
| 627 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 628 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 629 | * </ul> |
| 630 | * |
| 631 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 632 | * pixed density for the device. |
| 633 | * |
| 634 | * <p> If a content: URI is passed, the intent should have the flag |
| 635 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 636 | * {@link android.content.ClipData} of the intent too. |
| 637 | * |
| 638 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 639 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 640 | */ |
| 641 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 642 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 643 | |
| 644 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 645 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 646 | * during setup-wizard. |
| 647 | * |
| 648 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 649 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 650 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 651 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 652 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 653 | * |
| 654 | * @hide |
| 655 | */ |
| 656 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 657 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 658 | |
| 659 | /** |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 660 | * This MIME type is used for starting the Device Owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 661 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 662 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 663 | * A device owner has full control over the device. The device owner can not be modified by the |
| 664 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 665 | * reset. |
| 666 | * |
| 667 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 668 | * employee or client. |
| 669 | * |
| 670 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 671 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 672 | * <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] | 673 | * contains the following properties: |
| 674 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 675 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 676 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 677 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 678 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 679 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 680 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 681 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 682 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 683 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 684 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 685 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 686 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 687 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 688 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 689 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 690 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 691 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 692 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 693 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 694 | * 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] | 695 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 696 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 697 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 698 | */ |
| 699 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 700 | = "application/com.android.managedprovisioning"; |
| 701 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 702 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 703 | * Activity action: ask the user to add a new device administrator to the system. |
| 704 | * The desired policy is the ComponentName of the policy in the |
| 705 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 706 | * bring the user through adding the device administrator to the system (or |
| 707 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 708 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 709 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 710 | * field to provide the user with additional explanation (in addition |
| 711 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 712 | * |
| 713 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 714 | * user intervention). However, if your administrator has been updated and is requesting |
| 715 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 716 | * 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] | 717 | */ |
| 718 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 719 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 720 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 721 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 722 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 723 | * @hide |
| 724 | * 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] | 725 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 726 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 727 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 728 | * 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] | 729 | * to remotely control restrictions on the user. |
| 730 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 731 | * <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] | 732 | * result of whether or not the user approved the action. If approved, the result will |
| 733 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 734 | * as a profile owner. |
| 735 | * |
| 736 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 737 | * field to provide the user with additional explanation (in addition |
| 738 | * to your component's description) about what is being added. |
| 739 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 740 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 741 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 742 | */ |
| 743 | @SystemApi |
| 744 | public static final String ACTION_SET_PROFILE_OWNER |
| 745 | = "android.app.action.SET_PROFILE_OWNER"; |
| 746 | |
| 747 | /** |
| 748 | * @hide |
| 749 | * Name of the profile owner admin that controls the user. |
| 750 | */ |
| 751 | @SystemApi |
| 752 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 753 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 754 | |
| 755 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 756 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 757 | * 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] | 758 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 759 | * @hide |
| 760 | */ |
| 761 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 762 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 763 | |
| 764 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 765 | * Broadcast action: sent when the device owner is set or changed. |
| 766 | * |
| 767 | * This broadcast is sent only to the primary user. |
| 768 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 769 | */ |
| 770 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 771 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 772 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 773 | |
| 774 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 775 | * The ComponentName of the administrator component. |
| 776 | * |
| 777 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 778 | */ |
| 779 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 780 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 781 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 782 | * An optional CharSequence providing additional explanation for why the |
| 783 | * admin is being added. |
| 784 | * |
| 785 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 786 | */ |
| 787 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 788 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 789 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 790 | * Activity action: have the user enter a new password. This activity should |
| 791 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 792 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 793 | * enter a new password that meets the current requirements. You can use |
| 794 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 795 | * have the user select a new password in order to meet the current |
| 796 | * constraints. Upon being resumed from this activity, you can check the new |
| 797 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 798 | * |
| 799 | * If the intent is launched from within a managed profile with a profile |
| 800 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 801 | * this will trigger entering a new password for the parent of the profile. |
| 802 | * For all other cases it will trigger entering a new password for the user |
| 803 | * or profile it is launched from. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 804 | */ |
| 805 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 806 | public static final String ACTION_SET_NEW_PASSWORD |
| 807 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 808 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 809 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 810 | * Activity action: have the user enter a new password for the parent profile. |
| 811 | * If the intent is launched from within a managed profile, this will trigger |
| 812 | * entering a new password for the parent of the profile. In all other cases |
| 813 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 814 | */ |
| 815 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 816 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 817 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 818 | |
| 819 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 820 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 821 | * the parent profile to access intents sent from the managed profile. |
| 822 | * That is, when an app in the managed profile calls |
| 823 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 824 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 825 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 826 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 827 | |
| 828 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 829 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 830 | * the managed profile to access intents sent from the parent profile. |
| 831 | * That is, when an app in the parent profile calls |
| 832 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 833 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 834 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 835 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 836 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 837 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 838 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 839 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 840 | */ |
| 841 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 842 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 843 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 844 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 845 | /** |
| 846 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 847 | * Already granted or denied permissions are not affected by this. |
| 848 | */ |
| 849 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 850 | |
| 851 | /** |
| 852 | * Permission policy to always grant new permission requests for runtime permissions. |
| 853 | * Already granted or denied permissions are not affected by this. |
| 854 | */ |
| 855 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 856 | |
| 857 | /** |
| 858 | * Permission policy to always deny new permission requests for runtime permissions. |
| 859 | * Already granted or denied permissions are not affected by this. |
| 860 | */ |
| 861 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 862 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 863 | /** |
| 864 | * Runtime permission state: The user can manage the permission |
| 865 | * through the UI. |
| 866 | */ |
| 867 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 868 | |
| 869 | /** |
| 870 | * Runtime permission state: The permission is granted to the app |
| 871 | * and the user cannot manage the permission through the UI. |
| 872 | */ |
| 873 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 874 | |
| 875 | /** |
| 876 | * Runtime permission state: The permission is denied to the app |
| 877 | * and the user cannot manage the permission through the UI. |
| 878 | */ |
| 879 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 880 | |
| 881 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 882 | * No management for current user in-effect. This is the default. |
| 883 | * @hide |
| 884 | */ |
| 885 | public static final int STATE_USER_UNMANAGED = 0; |
| 886 | |
| 887 | /** |
| 888 | * Management partially setup, user setup needs to be completed. |
| 889 | * @hide |
| 890 | */ |
| 891 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 892 | |
| 893 | /** |
| 894 | * Management partially setup, user setup completed. |
| 895 | * @hide |
| 896 | */ |
| 897 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 898 | |
| 899 | /** |
| 900 | * Management setup and active on current user. |
| 901 | * @hide |
| 902 | */ |
| 903 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 904 | |
| 905 | /** |
| 906 | * Management partially setup on a managed profile. |
| 907 | * @hide |
| 908 | */ |
| 909 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 910 | |
| 911 | /** |
| 912 | * @hide |
| 913 | */ |
| 914 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 915 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 916 | @Retention(RetentionPolicy.SOURCE) |
| 917 | public @interface UserProvisioningState {} |
| 918 | |
| 919 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 920 | * Return true if the given administrator component is currently |
| 921 | * active (enabled) in the system. |
| 922 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 923 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 924 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /** |
| 928 | * @see #isAdminActive(ComponentName) |
| 929 | * @hide |
| 930 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 931 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 932 | if (mService != null) { |
| 933 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 934 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 935 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 936 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | return false; |
| 940 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 941 | /** |
| 942 | * Return true if the given administrator component is currently being removed |
| 943 | * for the user. |
| 944 | * @hide |
| 945 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 946 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 947 | if (mService != null) { |
| 948 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 949 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 950 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 951 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | return false; |
| 955 | } |
| 956 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 957 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 958 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 959 | * Return a list of all currently active device administrators' component |
| 960 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 961 | * returned. |
| 962 | */ |
| 963 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 964 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /** |
| 968 | * @see #getActiveAdmins() |
| 969 | * @hide |
| 970 | */ |
| 971 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 972 | if (mService != null) { |
| 973 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 974 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 975 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 976 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | return null; |
| 980 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 981 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 982 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 983 | * Used by package administration code to determine if a package can be stopped |
| 984 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 985 | * @hide |
| 986 | */ |
| 987 | public boolean packageHasActiveAdmins(String packageName) { |
| 988 | if (mService != null) { |
| 989 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 990 | return mService.packageHasActiveAdmins(packageName, myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 991 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 992 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | return false; |
| 996 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 997 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 998 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 999 | * Remove a current administration component. This can only be called |
| 1000 | * by the application that owns the administration component; if you |
| 1001 | * try to remove someone else's component, a security exception will be |
| 1002 | * thrown. |
| 1003 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1004 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1005 | if (mService != null) { |
| 1006 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1007 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1008 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1009 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1013 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1014 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1015 | * 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] | 1016 | * 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] | 1017 | * but requires additional policies after an upgrade. |
| 1018 | * |
| 1019 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 1020 | * an active administrator, or an exception will be thrown. |
| 1021 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 1022 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1023 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1024 | if (mService != null) { |
| 1025 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1026 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1027 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1028 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | return false; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1035 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1036 | * |
| 1037 | * @hide |
| 1038 | */ |
| 1039 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1040 | if (mService != null) { |
| 1041 | try { |
| 1042 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1043 | } catch (RemoteException e) { |
| 1044 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1045 | } |
| 1046 | } |
| 1047 | return false; |
| 1048 | } |
| 1049 | |
| 1050 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1051 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1052 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1053 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1054 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1055 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1056 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1057 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1058 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1059 | * recognition technology. This implies technologies that can recognize the identity of |
| 1060 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1061 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1062 | */ |
| 1063 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1064 | |
| 1065 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1066 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1067 | * 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] | 1068 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1069 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1070 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1071 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1072 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1073 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1074 | * password containing at least numeric characters. Note that quality |
| 1075 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1076 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1077 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1078 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1079 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1080 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1081 | * password containing at least numeric characters with no repeating (4444) |
| 1082 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1083 | * constants are ordered so that higher values are more restrictive. |
| 1084 | */ |
| 1085 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1086 | |
| 1087 | /** |
| 1088 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1089 | * password containing at least alphabetic (or other symbol) characters. |
| 1090 | * Note that quality constants are ordered so that higher values are more |
| 1091 | * restrictive. |
| 1092 | */ |
| 1093 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1094 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1095 | /** |
| 1096 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1097 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1098 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1099 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1100 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1101 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1102 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1103 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1104 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1105 | * password containing at least a letter, a numerical digit and a special |
| 1106 | * symbol, by default. With this password quality, passwords can be |
| 1107 | * restricted to contain various sets of characters, like at least an |
| 1108 | * uppercase letter, etc. These are specified using various methods, |
| 1109 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1110 | * that quality constants are ordered so that higher values are more |
| 1111 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1112 | */ |
| 1113 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1114 | |
| 1115 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1116 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1117 | * modify password. In case this password quality is set, the password is |
| 1118 | * managed by a profile owner. The profile owner can set any password, |
| 1119 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1120 | * that quality constants are ordered so that higher values are more |
| 1121 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1122 | * the highest. |
| 1123 | * @hide |
| 1124 | */ |
| 1125 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1126 | |
| 1127 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1128 | * Called by an application that is administering the device to set the |
| 1129 | * password restrictions it is imposing. After setting this, the user |
| 1130 | * will not be able to enter a new password that is not at least as |
| 1131 | * restrictive as what has been set. Note that the current password |
| 1132 | * will remain until the user has set a new one, so the change does not |
| 1133 | * take place immediately. To prompt the user for a new password, use |
| 1134 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1135 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1136 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 1137 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1138 | * the user's preference, and any other considerations) is the one that |
| 1139 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1140 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1141 | * <p>The calling device admin must have requested |
| 1142 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1143 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1144 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1145 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1146 | * @param quality The new desired quality. One of |
| 1147 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1148 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1149 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1150 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1151 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1152 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1153 | if (mService != null) { |
| 1154 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1155 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1156 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1157 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1161 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1162 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1163 | * Retrieve the current minimum password quality for all admins of this user |
| 1164 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1165 | * @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] | 1166 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1167 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1168 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1169 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1173 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1174 | if (mService != null) { |
| 1175 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1176 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1177 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1178 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1179 | } |
| 1180 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1181 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1182 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1183 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1184 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1185 | * Called by an application that is administering the device to set the |
| 1186 | * minimum allowed password length. After setting this, the user |
| 1187 | * will not be able to enter a new password that is not at least as |
| 1188 | * restrictive as what has been set. Note that the current password |
| 1189 | * will remain until the user has set a new one, so the change does not |
| 1190 | * take place immediately. To prompt the user for a new password, use |
| 1191 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1192 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1193 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1194 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1195 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1196 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1197 | * <p>The calling device admin must have requested |
| 1198 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1199 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1200 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1201 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1202 | * @param length The new desired minimum password length. A value of 0 |
| 1203 | * means there is no restriction. |
| 1204 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1205 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1206 | if (mService != null) { |
| 1207 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1208 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1209 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1210 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1214 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1215 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1216 | * Retrieve the current minimum password length for all admins of this |
| 1217 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1218 | * @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] | 1219 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1220 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1221 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1222 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1226 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1227 | if (mService != null) { |
| 1228 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1229 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1230 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1231 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | return 0; |
| 1235 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1236 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1237 | /** |
| 1238 | * Called by an application that is administering the device to set the |
| 1239 | * minimum number of upper case letters required in the password. After |
| 1240 | * setting this, the user will not be able to enter a new password that is |
| 1241 | * not at least as restrictive as what has been set. Note that the current |
| 1242 | * password will remain until the user has set a new one, so the change does |
| 1243 | * not take place immediately. To prompt the user for a new password, use |
| 1244 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1245 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1246 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1247 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1248 | * <p> |
| 1249 | * The calling device admin must have requested |
| 1250 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1251 | * this method; if it has not, a security exception will be thrown. |
| 1252 | * |
| 1253 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1254 | * with. |
| 1255 | * @param length The new desired minimum number of upper case letters |
| 1256 | * required in the password. A value of 0 means there is no |
| 1257 | * restriction. |
| 1258 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1259 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1260 | if (mService != null) { |
| 1261 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1262 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1263 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1264 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /** |
| 1270 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1271 | * password for all admins of this user and its profiles or a particular one. |
| 1272 | * This is the same value as set by |
| 1273 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1274 | * and only applies when the password quality is |
| 1275 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1276 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1277 | * @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] | 1278 | * aggregate all admins. |
| 1279 | * @return The minimum number of upper case letters required in the |
| 1280 | * password. |
| 1281 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1282 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1283 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1287 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1288 | if (mService != null) { |
| 1289 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1290 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1291 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1292 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * Called by an application that is administering the device to set the |
| 1300 | * minimum number of lower case letters required in the password. After |
| 1301 | * setting this, the user will not be able to enter a new password that is |
| 1302 | * not at least as restrictive as what has been set. Note that the current |
| 1303 | * password will remain until the user has set a new one, so the change does |
| 1304 | * not take place immediately. To prompt the user for a new password, use |
| 1305 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1306 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1307 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1308 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1309 | * <p> |
| 1310 | * The calling device admin must have requested |
| 1311 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1312 | * this method; if it has not, a security exception will be thrown. |
| 1313 | * |
| 1314 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1315 | * with. |
| 1316 | * @param length The new desired minimum number of lower case letters |
| 1317 | * required in the password. A value of 0 means there is no |
| 1318 | * restriction. |
| 1319 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1320 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1321 | if (mService != null) { |
| 1322 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1323 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1324 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1325 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | /** |
| 1331 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1332 | * password for all admins of this user and its profiles or a particular one. |
| 1333 | * This is the same value as set by |
| 1334 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1335 | * and only applies when the password quality is |
| 1336 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1337 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1338 | * @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] | 1339 | * aggregate all admins. |
| 1340 | * @return The minimum number of lower case letters required in the |
| 1341 | * password. |
| 1342 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1343 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1344 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1348 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1349 | if (mService != null) { |
| 1350 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1351 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1352 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1353 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * Called by an application that is administering the device to set the |
| 1361 | * minimum number of letters required in the password. After setting this, |
| 1362 | * the user will not be able to enter a new password that is not at least as |
| 1363 | * restrictive as what has been set. Note that the current password will |
| 1364 | * remain until the user has set a new one, so the change does not take |
| 1365 | * place immediately. To prompt the user for a new password, use |
| 1366 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1367 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1368 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1369 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1370 | * <p> |
| 1371 | * The calling device admin must have requested |
| 1372 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1373 | * this method; if it has not, a security exception will be thrown. |
| 1374 | * |
| 1375 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1376 | * with. |
| 1377 | * @param length The new desired minimum number of letters required in the |
| 1378 | * password. A value of 0 means there is no restriction. |
| 1379 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1380 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1381 | if (mService != null) { |
| 1382 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1383 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1384 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1385 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1392 | * admins or a particular one. This is the same value as |
| 1393 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 1394 | * and only applies when the password quality is |
| 1395 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1396 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1397 | * @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] | 1398 | * aggregate all admins. |
| 1399 | * @return The minimum number of letters required in the password. |
| 1400 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1401 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1402 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1406 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1407 | if (mService != null) { |
| 1408 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1409 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1410 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1411 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
| 1417 | /** |
| 1418 | * Called by an application that is administering the device to set the |
| 1419 | * minimum number of numerical digits required in the password. After |
| 1420 | * setting this, the user will not be able to enter a new password that is |
| 1421 | * not at least as restrictive as what has been set. Note that the current |
| 1422 | * password will remain until the user has set a new one, so the change does |
| 1423 | * not take place immediately. To prompt the user for a new password, use |
| 1424 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1425 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1426 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1427 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1428 | * <p> |
| 1429 | * The calling device admin must have requested |
| 1430 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1431 | * this method; if it has not, a security exception will be thrown. |
| 1432 | * |
| 1433 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1434 | * with. |
| 1435 | * @param length The new desired minimum number of numerical digits required |
| 1436 | * in the password. A value of 0 means there is no restriction. |
| 1437 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1438 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1439 | if (mService != null) { |
| 1440 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1441 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1442 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1443 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | /** |
| 1449 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1450 | * for all admins of this user and its profiles or a particular one. |
| 1451 | * This is the same value as set by |
| 1452 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1453 | * and only applies when the password quality is |
| 1454 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1455 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1456 | * @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] | 1457 | * aggregate all admins. |
| 1458 | * @return The minimum number of numerical digits required in the password. |
| 1459 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1460 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1461 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1465 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1466 | if (mService != null) { |
| 1467 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1468 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1469 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1470 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | return 0; |
| 1474 | } |
| 1475 | |
| 1476 | /** |
| 1477 | * Called by an application that is administering the device to set the |
| 1478 | * minimum number of symbols required in the password. After setting this, |
| 1479 | * the user will not be able to enter a new password that is not at least as |
| 1480 | * restrictive as what has been set. Note that the current password will |
| 1481 | * remain until the user has set a new one, so the change does not take |
| 1482 | * place immediately. To prompt the user for a new password, use |
| 1483 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1484 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1485 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1486 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1487 | * <p> |
| 1488 | * The calling device admin must have requested |
| 1489 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1490 | * this method; if it has not, a security exception will be thrown. |
| 1491 | * |
| 1492 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1493 | * with. |
| 1494 | * @param length The new desired minimum number of symbols required in the |
| 1495 | * password. A value of 0 means there is no restriction. |
| 1496 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1497 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1498 | if (mService != null) { |
| 1499 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1500 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1501 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1502 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1503 | } |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1509 | * admins or a particular one. This is the same value as |
| 1510 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1511 | * and only applies when the password quality is |
| 1512 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1513 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1514 | * @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] | 1515 | * aggregate all admins. |
| 1516 | * @return The minimum number of symbols required in the password. |
| 1517 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1518 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1519 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1523 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1524 | if (mService != null) { |
| 1525 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1526 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1527 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1528 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1534 | /** |
| 1535 | * Called by an application that is administering the device to set the |
| 1536 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1537 | * required in the password. After setting this, the user will not be able |
| 1538 | * to enter a new password that is not at least as restrictive as what has |
| 1539 | * been set. Note that the current password will remain until the user has |
| 1540 | * set a new one, so the change does not take place immediately. To prompt |
| 1541 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1542 | * setting this value. This constraint is only imposed if the administrator |
| 1543 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1544 | * {@link #setPasswordQuality}. The default value is 0. |
| 1545 | * <p> |
| 1546 | * The calling device admin must have requested |
| 1547 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1548 | * this method; if it has not, a security exception will be thrown. |
| 1549 | * |
| 1550 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1551 | * with. |
| 1552 | * @param length The new desired minimum number of letters required in the |
| 1553 | * password. A value of 0 means there is no restriction. |
| 1554 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1555 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1556 | if (mService != null) { |
| 1557 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1558 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1559 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1560 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | /** |
| 1566 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1567 | * password for all admins of this user and its profiles or a particular one. |
| 1568 | * This is the same value as set by |
| 1569 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1570 | * and only applies when the password quality is |
| 1571 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1572 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1573 | * @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] | 1574 | * aggregate all admins. |
| 1575 | * @return The minimum number of letters required in the password. |
| 1576 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1577 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1578 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1582 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1583 | if (mService != null) { |
| 1584 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1585 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1586 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1587 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1588 | } |
| 1589 | } |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1593 | /** |
| 1594 | * Called by an application that is administering the device to set the length |
| 1595 | * of the password history. After setting this, the user will not be able to |
| 1596 | * enter a new password that is the same as any password in the history. Note |
| 1597 | * that the current password will remain until the user has set a new one, so |
| 1598 | * the change does not take place immediately. To prompt the user for a new |
| 1599 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1600 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1601 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1602 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1603 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1604 | * |
| 1605 | * <p> |
| 1606 | * The calling device admin must have requested |
| 1607 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1608 | * method; if it has not, a security exception will be thrown. |
| 1609 | * |
| 1610 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1611 | * with. |
| 1612 | * @param length The new desired length of password history. A value of 0 |
| 1613 | * means there is no restriction. |
| 1614 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1615 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1616 | if (mService != null) { |
| 1617 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1618 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1619 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1620 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1626 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1627 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1628 | * the device password (for all admins). |
| 1629 | * |
| 1630 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1631 | * For example, to have the password expire 5 days from now, timeout would be |
| 1632 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1633 | * |
| 1634 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1635 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1636 | * <p>The calling device admin must have requested |
| 1637 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1638 | * method; if it has not, a security exception will be thrown. |
| 1639 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1640 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1641 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1642 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1643 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1644 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1645 | * means there is no restriction (unlimited). |
| 1646 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1647 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1648 | if (mService != null) { |
| 1649 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1650 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1651 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1652 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1658 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1659 | * recurring expiration timeout provided in the call to |
| 1660 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1661 | * aggregate of all policy administrators if {@code admin} is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1662 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1663 | * @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] | 1664 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1665 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1666 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1667 | if (mService != null) { |
| 1668 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1669 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1670 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1671 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | return 0; |
| 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * 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] | 1679 | * all admins of this user and its profiles if admin is null. If the password is |
| 1680 | * expired, this will return the time since the password expired as a negative number. |
| 1681 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1682 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1683 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1684 | * @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] | 1685 | * @return The password expiration time, in ms. |
| 1686 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1687 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1688 | if (mService != null) { |
| 1689 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1690 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1691 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1692 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1693 | } |
| 1694 | } |
| 1695 | return 0; |
| 1696 | } |
| 1697 | |
| 1698 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1699 | * Retrieve the current password history length for all admins of this |
| 1700 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1701 | * @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] | 1702 | * all admins. |
| 1703 | * @return The length of the password history |
| 1704 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1705 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1706 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1710 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1711 | if (mService != null) { |
| 1712 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1713 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1714 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1715 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1721 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1722 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1723 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1724 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1725 | * @return Returns the maximum length that the user can enter. |
| 1726 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1727 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1728 | // Kind-of arbitrary. |
| 1729 | return 16; |
| 1730 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1731 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1732 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1733 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1734 | * to meet the policy requirements (quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1735 | * 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] | 1736 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1737 | * <p>The calling device admin must have requested |
| 1738 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1739 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1740 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1741 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1742 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1743 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1744 | if (mService != null) { |
| 1745 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1746 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1747 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1748 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1749 | } |
| 1750 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1751 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1752 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1753 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1754 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1755 | * Determine whether the current profile password the user has set is sufficient |
| 1756 | * to meet the policy requirements (quality, minimum length) that have been |
| 1757 | * requested by the admins of the parent user and its profiles. |
| 1758 | * |
| 1759 | * @param userHandle the userId of the profile to check the password for. |
| 1760 | * @return Returns true if the password would meet the current requirements, else false. |
| 1761 | * @hide |
| 1762 | */ |
| 1763 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 1764 | if (mService != null) { |
| 1765 | try { |
| 1766 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 1767 | } catch (RemoteException e) { |
| 1768 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1769 | } |
| 1770 | } |
| 1771 | return false; |
| 1772 | } |
| 1773 | |
| 1774 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1775 | * Retrieve the number of times the user has failed at entering a |
| 1776 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1777 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1778 | * <p>The calling device admin must have requested |
| 1779 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1780 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1781 | */ |
| 1782 | public int getCurrentFailedPasswordAttempts() { |
| 1783 | if (mService != null) { |
| 1784 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1785 | return mService.getCurrentFailedPasswordAttempts(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1786 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1787 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1788 | } |
| 1789 | } |
| 1790 | return -1; |
| 1791 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1792 | |
| 1793 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1794 | * 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] | 1795 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1796 | * @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] | 1797 | * @hide |
| 1798 | */ |
| 1799 | public boolean getDoNotAskCredentialsOnBoot() { |
| 1800 | if (mService != null) { |
| 1801 | try { |
| 1802 | return mService.getDoNotAskCredentialsOnBoot(); |
| 1803 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1804 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | return false; |
| 1808 | } |
| 1809 | |
| 1810 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1811 | * Setting this to a value greater than zero enables a built-in policy |
| 1812 | * that will perform a device wipe after too many incorrect |
| 1813 | * device-unlock passwords have been entered. This built-in policy combines |
| 1814 | * watching for failed passwords and wiping the device, and requires |
| 1815 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1816 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1817 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1818 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1819 | * application only, erasing or revoking credentials, or reporting the |
| 1820 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1821 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1822 | * instead. Do not use this API, because if the maximum count is reached, |
| 1823 | * 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] | 1824 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1825 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1826 | * @param num The number of failed password attempts at which point the |
| 1827 | * device will wipe its data. |
| 1828 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1829 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1830 | if (mService != null) { |
| 1831 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1832 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1833 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1834 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1835 | } |
| 1836 | } |
| 1837 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1838 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1839 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1840 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1841 | * 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] | 1842 | * or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1843 | * @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] | 1844 | * all admins. |
| 1845 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1846 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1847 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1851 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1852 | if (mService != null) { |
| 1853 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1854 | return mService.getMaximumFailedPasswordsForWipe( |
| 1855 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1856 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1857 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1858 | } |
| 1859 | } |
| 1860 | return 0; |
| 1861 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1862 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1863 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1864 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1865 | * for the given user. So for primary user, it might return the primary or |
| 1866 | * a managed profile. For a secondary user, it would be the same as the |
| 1867 | * user passed in. |
| 1868 | * @hide Used only by Keyguard |
| 1869 | */ |
| 1870 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1871 | if (mService != null) { |
| 1872 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1873 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 1874 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1875 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1876 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | return UserHandle.USER_NULL; |
| 1880 | } |
| 1881 | |
| 1882 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1883 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1884 | * the password again until the user has entered it. |
| 1885 | */ |
| 1886 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1887 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1888 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1889 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 1890 | * If the flag is set, the device can be booted without asking for user password. |
| 1891 | * The absence of this flag does not change the current boot requirements. This flag |
| 1892 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 1893 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 1894 | * device to factory defaults. |
| 1895 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1896 | 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] | 1897 | |
| 1898 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1899 | * Force a new device unlock password (the password needed to access the |
| 1900 | * entire device, not for individual accounts) on the user. This takes |
| 1901 | * effect immediately. |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 1902 | * |
| 1903 | * <p>Calling this from a managed profile that shares the password with the owner profile |
| 1904 | * will throw a security exception. |
| 1905 | * |
| 1906 | * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
| 1907 | * device admins that are not device owner and not profile owner. |
| 1908 | * The password can now only be changed if there is currently no password set. Device owner |
| 1909 | * and profile owner can still do this.</em> |
| 1910 | * |
| 1911 | * <p>The given password must be sufficient for the |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1912 | * current password quality and length constraints as returned by |
| 1913 | * {@link #getPasswordQuality(ComponentName)} and |
| 1914 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1915 | * these constraints, then it will be rejected and false returned. Note |
| 1916 | * that the password may be a stronger quality (containing alphanumeric |
| 1917 | * characters when the requested quality is only numeric), in which case |
| 1918 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1919 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1920 | * <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] | 1921 | * pattern or password if the current password constraints allow it. <em>Note: This will not |
| 1922 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 1923 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 1924 | * empty, except by device owner or profile owner.</em> |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1925 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1926 | * <p>The calling device admin must have requested |
| 1927 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1928 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1929 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1930 | * @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] | 1931 | * @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] | 1932 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1933 | * @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] | 1934 | * 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] | 1935 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1936 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1937 | if (mParentInstance) { |
| 1938 | throw new SecurityException("Reset password does not work across profiles."); |
| 1939 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1940 | if (mService != null) { |
| 1941 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1942 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1943 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1944 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1945 | } |
| 1946 | } |
| 1947 | return false; |
| 1948 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1949 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1950 | /** |
| 1951 | * Called by an application that is administering the device to set the |
| 1952 | * maximum time for user activity until the device will lock. This limits |
| 1953 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1954 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1955 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1956 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1957 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1958 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1959 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1960 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1961 | * A value of 0 means there is no restriction. |
| 1962 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1963 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1964 | if (mService != null) { |
| 1965 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1966 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1967 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1968 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1969 | } |
| 1970 | } |
| 1971 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1972 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1973 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1974 | * Retrieve the current maximum time to unlock for all admins of this user |
| 1975 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1976 | * @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] | 1977 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 1978 | * @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] | 1979 | * 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] | 1980 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1981 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1982 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1986 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1987 | if (mService != null) { |
| 1988 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1989 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1990 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1991 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | return 0; |
| 1995 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1996 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1997 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1998 | * Make the device lock immediately, as if the lock screen timeout has |
| 1999 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2000 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2001 | * <p>The calling device admin must have requested |
| 2002 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 2003 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2004 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2005 | public void lockNow() { |
| 2006 | if (mService != null) { |
| 2007 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2008 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2009 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2010 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2014 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2015 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2016 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2017 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2018 | */ |
| 2019 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2020 | |
| 2021 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2022 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2023 | * data. |
| 2024 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2025 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2026 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2027 | */ |
| 2028 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2029 | |
| 2030 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 2031 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 2032 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2033 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2034 | * <p>The calling device admin must have requested |
| 2035 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 2036 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2037 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2038 | * @param flags Bit mask of additional options: currently supported flags |
| 2039 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 2040 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2041 | */ |
| 2042 | public void wipeData(int flags) { |
| 2043 | if (mService != null) { |
| 2044 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2045 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2046 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2047 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2048 | } |
| 2049 | } |
| 2050 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2051 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2052 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2053 | * Called by an application that is administering the device to set the |
| 2054 | * global proxy and exclusion list. |
| 2055 | * <p> |
| 2056 | * The calling device admin must have requested |
| 2057 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2058 | * this method; if it has not, a security exception will be thrown. |
| 2059 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2060 | * 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] | 2061 | * 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] | 2062 | * be returned. |
| 2063 | * The method can be called repeatedly by the device admin alrady setting the |
| 2064 | * proxy to update the proxy and exclusion list. |
| 2065 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2066 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2067 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2068 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2069 | * @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] | 2070 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2071 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2072 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2073 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2074 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2075 | List<String> exclusionList ) { |
| 2076 | if (proxySpec == null) { |
| 2077 | throw new NullPointerException(); |
| 2078 | } |
| 2079 | if (mService != null) { |
| 2080 | try { |
| 2081 | String hostSpec; |
| 2082 | String exclSpec; |
| 2083 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2084 | hostSpec = null; |
| 2085 | exclSpec = null; |
| 2086 | } else { |
| 2087 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2088 | throw new IllegalArgumentException(); |
| 2089 | } |
| 2090 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2091 | String hostName = sa.getHostName(); |
| 2092 | int port = sa.getPort(); |
| 2093 | StringBuilder hostBuilder = new StringBuilder(); |
| 2094 | hostSpec = hostBuilder.append(hostName) |
| 2095 | .append(":").append(Integer.toString(port)).toString(); |
| 2096 | if (exclusionList == null) { |
| 2097 | exclSpec = ""; |
| 2098 | } else { |
| 2099 | StringBuilder listBuilder = new StringBuilder(); |
| 2100 | boolean firstDomain = true; |
| 2101 | for (String exclDomain : exclusionList) { |
| 2102 | if (!firstDomain) { |
| 2103 | listBuilder = listBuilder.append(","); |
| 2104 | } else { |
| 2105 | firstDomain = false; |
| 2106 | } |
| 2107 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2108 | } |
| 2109 | exclSpec = listBuilder.toString(); |
| 2110 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2111 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2112 | != android.net.Proxy.PROXY_VALID) |
| 2113 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2114 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2115 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2116 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2117 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | return null; |
| 2121 | } |
| 2122 | |
| 2123 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2124 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 2125 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 2126 | * doing something unusual like general internal filtering this may be useful. On |
| 2127 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 2128 | * |
| 2129 | * <p>This method requires the caller to be the device owner. |
| 2130 | * |
| 2131 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 2132 | * @see ProxyInfo |
| 2133 | * |
| 2134 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2135 | * with. |
| 2136 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 2137 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 2138 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2139 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2140 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2141 | if (mService != null) { |
| 2142 | try { |
| 2143 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2144 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2145 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2151 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2152 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2153 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2154 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2155 | */ |
| 2156 | public ComponentName getGlobalProxyAdmin() { |
| 2157 | if (mService != null) { |
| 2158 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2159 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2160 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2161 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2162 | } |
| 2163 | } |
| 2164 | return null; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2168 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2169 | * indicating that encryption is not supported. |
| 2170 | */ |
| 2171 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2172 | |
| 2173 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2174 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2175 | * indicating that encryption is supported, but is not currently active. |
| 2176 | */ |
| 2177 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2178 | |
| 2179 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2180 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2181 | * indicating that encryption is not currently active, but is currently |
| 2182 | * being activated. This is only reported by devices that support |
| 2183 | * encryption of data and only when the storage is currently |
| 2184 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2185 | * to become encrypted will never return this value. |
| 2186 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2187 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2188 | |
| 2189 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2190 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2191 | * indicating that encryption is active. |
| 2192 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2193 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2194 | |
| 2195 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2196 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2197 | * indicating that encryption is active, but an encryption key has not |
| 2198 | * been set by the user. |
| 2199 | */ |
| 2200 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2201 | |
| 2202 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2203 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2204 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2205 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2206 | * to check encryption status. However, on some devices this activity may never return, as |
| 2207 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2208 | */ |
| 2209 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2210 | public static final String ACTION_START_ENCRYPTION |
| 2211 | = "android.app.action.START_ENCRYPTION"; |
| 2212 | |
| 2213 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2214 | * Widgets are enabled in keyguard |
| 2215 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2216 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2217 | |
| 2218 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2219 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2220 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2221 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2222 | |
| 2223 | /** |
| 2224 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2225 | */ |
| 2226 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2227 | |
| 2228 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2229 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2230 | */ |
| 2231 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2232 | |
| 2233 | /** |
| 2234 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2235 | */ |
| 2236 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2237 | |
| 2238 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2239 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2240 | * (e.g. PIN/Pattern/Password). |
| 2241 | */ |
| 2242 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2243 | |
| 2244 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2245 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2246 | */ |
| 2247 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2248 | |
| 2249 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2250 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2251 | */ |
| 2252 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2253 | |
| 2254 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2255 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2256 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2257 | * |
| 2258 | * <p>When multiple device administrators attempt to control device |
| 2259 | * encryption, the most secure, supported setting will always be |
| 2260 | * used. If any device administrator requests device encryption, |
| 2261 | * it will be enabled; Conversely, if a device administrator |
| 2262 | * attempts to disable device encryption while another |
| 2263 | * device administrator has enabled it, the call to disable will |
| 2264 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2265 | * |
| 2266 | * <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] | 2267 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2268 | * or control the encryption of any other storage areas. |
| 2269 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2270 | * {@code true}, then the directory returned by |
| 2271 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2272 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2273 | * |
| 2274 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2275 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2276 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2277 | * also require (and check for) a pattern, PIN, or password. |
| 2278 | * |
| 2279 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2280 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2281 | * @return the new request status (for all active admins) - will be one of |
| 2282 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2283 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2284 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2285 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2286 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2287 | if (mService != null) { |
| 2288 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2289 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2290 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2291 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2292 | } |
| 2293 | } |
| 2294 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2295 | } |
| 2296 | |
| 2297 | /** |
| 2298 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2299 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2300 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2301 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2302 | * this will return the requested encryption setting as an aggregate of all active |
| 2303 | * administrators. |
| 2304 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2305 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2306 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2307 | if (mService != null) { |
| 2308 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2309 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2310 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2311 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2312 | } |
| 2313 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2314 | return false; |
| 2315 | } |
| 2316 | |
| 2317 | /** |
| 2318 | * Called by an application that is administering the device to |
| 2319 | * determine the current encryption status of the device. |
| 2320 | * |
| 2321 | * Depending on the returned status code, the caller may proceed in different |
| 2322 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2323 | * storage system does not support encryption. If the |
| 2324 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2325 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2326 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2327 | * storage system has enabled encryption but no password is set so further action |
| 2328 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2329 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2330 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2331 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2332 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2333 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2334 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2335 | */ |
| 2336 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2337 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | /** @hide per-user version */ |
| 2341 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2342 | if (mService != null) { |
| 2343 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2344 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2345 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2346 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2347 | } |
| 2348 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2349 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2350 | } |
| 2351 | |
| 2352 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2353 | * Installs the given certificate as a user CA. |
| 2354 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2355 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2356 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2357 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2358 | * |
| 2359 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2360 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2361 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2362 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2363 | if (mService != null) { |
| 2364 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2365 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2366 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2367 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2368 | } |
| 2369 | } |
| 2370 | return false; |
| 2371 | } |
| 2372 | |
| 2373 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2374 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2375 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2376 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2377 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2378 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2379 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2380 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2381 | if (mService != null) { |
| 2382 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2383 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2384 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2385 | } catch (CertificateException e) { |
| 2386 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2387 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2388 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2394 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2395 | * If a user has installed any certificates by other means than device policy these will be |
| 2396 | * included too. |
| 2397 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2398 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2399 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2400 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2401 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2402 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2403 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2404 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2405 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2406 | mService.enforceCanManageCaCerts(admin); |
| 2407 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2408 | for (String alias : certStore.userAliases()) { |
| 2409 | try { |
| 2410 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2411 | } catch (CertificateException ce) { |
| 2412 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2413 | } |
| 2414 | } |
| 2415 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2416 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2423 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2424 | * means other than device policy will also be removed, except for system CA certificates. |
| 2425 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2426 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2427 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2429 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2430 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2431 | try { |
| 2432 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2433 | .toArray(new String[0])); |
| 2434 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2435 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * Returns whether this certificate is installed as a trusted CA. |
| 2442 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2443 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2444 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2445 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2446 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2447 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2448 | if (mService != null) { |
| 2449 | try { |
| 2450 | mService.enforceCanManageCaCerts(admin); |
| 2451 | return getCaCertAlias(certBuffer) != null; |
| 2452 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2453 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2454 | } catch (CertificateException ce) { |
| 2455 | Log.w(TAG, "Could not parse certificate", ce); |
| 2456 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2457 | } |
| 2458 | return false; |
| 2459 | } |
| 2460 | |
| 2461 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2462 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 2463 | * keypair will be visible to all apps within the profile. |
| 2464 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2465 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2466 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2467 | * @param privKey The private key to install. |
| 2468 | * @param cert The certificate to install. |
| 2469 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2470 | * with that alias already exists, it will be overwritten. |
| 2471 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2472 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2473 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2474 | @NonNull Certificate cert, @NonNull String alias) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2475 | try { |
| 2476 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2477 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2478 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2479 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2480 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2481 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2482 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2483 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2484 | } catch (CertificateException | IOException e) { |
| 2485 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2486 | } |
| 2487 | return false; |
| 2488 | } |
| 2489 | |
| 2490 | /** |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2491 | * Called by a device or profile owner to remove all user credentials installed under a given |
| 2492 | * alias. |
| 2493 | * |
| 2494 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2495 | * {@code null} if calling from a delegated certificate installer. |
| 2496 | * @param alias The private key alias under which the certificate is installed. |
| 2497 | * @return {@code true} if the keys were both removed, {@code false} otherwise. |
| 2498 | */ |
| 2499 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2500 | try { |
| 2501 | return mService.removeKeyPair(admin, alias); |
| 2502 | } catch (RemoteException e) { |
| 2503 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2504 | } |
| 2505 | return false; |
| 2506 | } |
| 2507 | |
| 2508 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2509 | * @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] | 2510 | * doesn't exist. |
| 2511 | */ |
| 2512 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2513 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2514 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2515 | new ByteArrayInputStream(certBuffer)); |
| 2516 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2517 | } |
| 2518 | |
| 2519 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2520 | * 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] | 2521 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2522 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2523 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2524 | * <p> |
| 2525 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2526 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2527 | * installer. |
| 2528 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2529 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2530 | * @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] | 2531 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2532 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2533 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2534 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2535 | if (mService != null) { |
| 2536 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2537 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2538 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2539 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | |
| 2544 | /** |
| 2545 | * 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] | 2546 | * user. null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2547 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2548 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2549 | * @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] | 2550 | * if none is set. |
| 2551 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2552 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2553 | if (mService != null) { |
| 2554 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2555 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2556 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2557 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2558 | } |
| 2559 | } |
| 2560 | return null; |
| 2561 | } |
| 2562 | |
| 2563 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2564 | * Called by a device or profile owner to configure an always-on VPN connection through a |
| 2565 | * specific application for the current user. |
| 2566 | * This connection is automatically granted and persisted after a reboot. |
| 2567 | * |
| 2568 | * <p>The designated package should declare a {@link android.net.VpnService} in its |
| 2569 | * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, |
| 2570 | * otherwise the call will fail. |
| 2571 | * |
| 2572 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} |
| 2573 | * to remove an existing always-on VPN configuration. |
| 2574 | * |
| 2575 | * @return {@code true} if the package is set as always-on VPN controller; |
| 2576 | * {@code false} otherwise. |
| 2577 | */ |
| 2578 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2579 | @Nullable String vpnPackage) { |
| 2580 | if (mService != null) { |
| 2581 | try { |
| 2582 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2583 | } catch (RemoteException e) { |
| 2584 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2585 | } |
| 2586 | } |
| 2587 | return false; |
| 2588 | } |
| 2589 | |
| 2590 | /** |
| 2591 | * Called by a device or profile owner to read the name of the package administering an |
| 2592 | * always-on VPN connection for the current user. |
| 2593 | * If there is no such package, or the always-on VPN is provided by the system instead |
| 2594 | * of by an application, {@code null} will be returned. |
| 2595 | * |
| 2596 | * @return Package name of VPN controller responsible for always-on VPN, |
| 2597 | * or {@code null} if none is set. |
| 2598 | */ |
| 2599 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2600 | if (mService != null) { |
| 2601 | try { |
| 2602 | return mService.getAlwaysOnVpnPackage(admin); |
| 2603 | } catch (RemoteException e) { |
| 2604 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2605 | } |
| 2606 | } |
| 2607 | return null; |
| 2608 | } |
| 2609 | |
| 2610 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2611 | * 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] | 2612 | * on the device, for this user. After setting this, no applications running as this user |
| 2613 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2614 | * |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 2615 | * <p>If the caller is device owner, then the restriction will be applied to all users. |
| 2616 | * |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2617 | * <p>The calling device admin must have requested |
| 2618 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2619 | * this method; if it has not, a security exception will be thrown. |
| 2620 | * |
| 2621 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2622 | * @param disabled Whether or not the camera should be disabled. |
| 2623 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2624 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2625 | if (mService != null) { |
| 2626 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2627 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2628 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2629 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2635 | * 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] | 2636 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2637 | * @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] | 2638 | * have disabled the camera |
| 2639 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2640 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2641 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2645 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2646 | if (mService != null) { |
| 2647 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2648 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2649 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2650 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2651 | } |
| 2652 | } |
| 2653 | return false; |
| 2654 | } |
| 2655 | |
| 2656 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2657 | * Called by a device owner to request a bugreport. |
| 2658 | * |
| 2659 | * <p>There must be only one user on the device, managed by the device owner. |
| 2660 | * Otherwise a security exception will be thrown. |
| 2661 | * |
| 2662 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2663 | * @return {@code true} if the bugreport collection started successfully, or {@code false} |
| 2664 | * if it wasn't triggered because a previous bugreport operation is still active |
| 2665 | * (either the bugreport is still running or waiting for the user to share or decline) |
| 2666 | */ |
| 2667 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 2668 | if (mService != null) { |
| 2669 | try { |
| 2670 | return mService.requestBugreport(admin); |
| 2671 | } catch (RemoteException e) { |
| 2672 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2673 | } |
| 2674 | } |
| 2675 | return false; |
| 2676 | } |
| 2677 | |
| 2678 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2679 | * Determine whether or not creating a guest user has been disabled for the device |
| 2680 | * |
| 2681 | * @hide |
| 2682 | */ |
| 2683 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 2684 | // Currently guest users can always be created if multi-user is enabled |
| 2685 | // TODO introduce a policy for guest user creation |
| 2686 | return false; |
| 2687 | } |
| 2688 | |
| 2689 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2690 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2691 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2692 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2693 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2694 | * |
| 2695 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2696 | * security exception will be thrown. |
| 2697 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2698 | * <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] | 2699 | * blocks assist requests for all activities of the relevant user. |
| 2700 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2701 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2702 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2703 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2704 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2705 | if (mService != null) { |
| 2706 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2707 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2708 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2709 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2710 | } |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2715 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2716 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2717 | * @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] | 2718 | * have disabled screen capture. |
| 2719 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2720 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2721 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2725 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2726 | if (mService != null) { |
| 2727 | try { |
| 2728 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2729 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2730 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | return false; |
| 2734 | } |
| 2735 | |
| 2736 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2737 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2738 | * required the user cannot set the date and time, but has to use network date and time. |
| 2739 | * |
| 2740 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2741 | * |
| 2742 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2743 | * be thrown. |
| 2744 | * |
| 2745 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2746 | * @param required Whether auto time is set required or not. |
| 2747 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2748 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2749 | if (mService != null) { |
| 2750 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2751 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2752 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2753 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2754 | } |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | /** |
| 2759 | * @return true if auto time is required. |
| 2760 | */ |
| 2761 | public boolean getAutoTimeRequired() { |
| 2762 | if (mService != null) { |
| 2763 | try { |
| 2764 | return mService.getAutoTimeRequired(); |
| 2765 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2766 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | return false; |
| 2770 | } |
| 2771 | |
| 2772 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2773 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2774 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2775 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2776 | * |
| 2777 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2778 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2779 | * this method; if it has not, a security exception will be thrown. |
| 2780 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2781 | * <p>Calling this from a managed profile before version |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2782 | * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2783 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2784 | * <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] | 2785 | * <ul> |
| 2786 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT} |
| 2787 | * these will affect the profile's parent user. |
| 2788 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications |
| 2789 | * generated by applications in the managed profile. |
| 2790 | * </ul> |
| 2791 | * <p>Requests to disable other features on a managed profile will be ignored. The admin |
| 2792 | * can check which features have been disabled by calling |
| 2793 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2794 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2795 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2796 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2797 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2798 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2799 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 2800 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2801 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2802 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2803 | if (mService != null) { |
| 2804 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2805 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2806 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2807 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2808 | } |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2813 | * 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] | 2814 | * admin, if specified, or all admins. |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2815 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 2816 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2817 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2818 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2819 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2820 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2821 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2825 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2826 | if (mService != null) { |
| 2827 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2828 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2829 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2830 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2831 | } |
| 2832 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2833 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2837 | * @hide |
| 2838 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2839 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 2840 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2841 | if (mService != null) { |
| 2842 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2843 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2844 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2845 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2849 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2850 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2851 | * @hide |
| 2852 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2853 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2854 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2858 | * 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] | 2859 | * @hide |
| 2860 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2861 | public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2862 | ActivityInfo ai; |
| 2863 | try { |
| 2864 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2865 | PackageManager.GET_META_DATA); |
| 2866 | } catch (PackageManager.NameNotFoundException e) { |
| 2867 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2868 | return null; |
| 2869 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2870 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2871 | ResolveInfo ri = new ResolveInfo(); |
| 2872 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2873 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2874 | try { |
| 2875 | return new DeviceAdminInfo(mContext, ri); |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2876 | } catch (XmlPullParserException | IOException e) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2877 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2878 | return null; |
| 2879 | } |
| 2880 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2881 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2882 | /** |
| 2883 | * @hide |
| 2884 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2885 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2886 | if (mService != null) { |
| 2887 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2888 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2889 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2890 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2891 | } |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | /** |
| 2896 | * @hide |
| 2897 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2898 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2899 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2900 | if (mService != null) { |
| 2901 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2902 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2903 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2904 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2905 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2906 | } |
| 2907 | } |
| 2908 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2909 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2910 | /** |
| 2911 | * @hide |
| 2912 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2913 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2914 | if (mService != null) { |
| 2915 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2916 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2917 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2918 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2919 | } |
| 2920 | } |
| 2921 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2922 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2923 | /** |
| 2924 | * @hide |
| 2925 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2926 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2927 | if (mService != null) { |
| 2928 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2929 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2930 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2931 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2932 | } |
| 2933 | } |
| 2934 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2935 | |
| 2936 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame^] | 2937 | * Should be called when keyguard has been dismissed. |
| 2938 | * @hide |
| 2939 | */ |
| 2940 | public void reportKeyguardDismissed() { |
| 2941 | if (mService != null) { |
| 2942 | try { |
| 2943 | mService.reportKeyguardDismissed(); |
| 2944 | } catch (RemoteException e) { |
| 2945 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2946 | } |
| 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | /** |
| 2951 | * Should be called when keyguard view has been shown to the user. |
| 2952 | * @hide |
| 2953 | */ |
| 2954 | public void reportKeyguardSecured() { |
| 2955 | if (mService != null) { |
| 2956 | try { |
| 2957 | mService.reportKeyguardSecured(); |
| 2958 | } catch (RemoteException e) { |
| 2959 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2960 | } |
| 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2965 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2966 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 2967 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 2968 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2969 | * @return whether the package was successfully registered as the device owner. |
| 2970 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2971 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2972 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 2973 | public boolean setDeviceOwner(ComponentName who) { |
| 2974 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | /** |
| 2978 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 2979 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 2980 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 2981 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | /** |
| 2985 | * @hide |
| 2986 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 2987 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 2988 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | /** |
| 2992 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2993 | * Sets the given package as the device owner. The package must already be installed. There |
| 2994 | * must not already be a device owner. |
| 2995 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 2996 | * this method. |
| 2997 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 2998 | * 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] | 2999 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3000 | * @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] | 3001 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3002 | * @return whether the package was successfully registered as the device owner. |
| 3003 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3004 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3005 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3006 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3007 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3008 | if (mService != null) { |
| 3009 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3010 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3011 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3012 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3013 | } |
| 3014 | } |
| 3015 | return false; |
| 3016 | } |
| 3017 | |
| 3018 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3019 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3020 | * 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] | 3021 | * 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] | 3022 | * package is currently registered as the device owner app, pass in the package name from |
| 3023 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3024 | * 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] | 3025 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3026 | * the setup process. |
| 3027 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3028 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3029 | * @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] | 3030 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3031 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3032 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3033 | } |
| 3034 | |
| 3035 | /** |
| 3036 | * @return true if a package is registered as device owner, only when it's running on the |
| 3037 | * calling user. |
| 3038 | * |
| 3039 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3040 | * @hide |
| 3041 | */ |
| 3042 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3043 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3048 | * user. |
| 3049 | * |
| 3050 | * <p>Requires the MANAGE_USERS permission. |
| 3051 | * |
| 3052 | * @hide |
| 3053 | */ |
| 3054 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3055 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3056 | } |
| 3057 | |
| 3058 | /** |
| 3059 | * @return device owner component name, only when it's running on the calling user. |
| 3060 | * |
| 3061 | * @hide |
| 3062 | */ |
| 3063 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3064 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3065 | } |
| 3066 | |
| 3067 | /** |
| 3068 | * @return device owner component name, even if it's running on a different user. |
| 3069 | * |
| 3070 | * <p>Requires the MANAGE_USERS permission. |
| 3071 | * |
| 3072 | * @hide |
| 3073 | */ |
| 3074 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3075 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3076 | } |
| 3077 | |
| 3078 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3079 | if (packageName == null) { |
| 3080 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3081 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3082 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3083 | if (deviceOwner == null) { |
| 3084 | return false; |
| 3085 | } |
| 3086 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3087 | } |
| 3088 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3089 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3090 | if (mService != null) { |
| 3091 | try { |
| 3092 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3093 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3094 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3100 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3101 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3102 | * no device owner. |
| 3103 | * |
| 3104 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3105 | * |
| 3106 | * @hide |
| 3107 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3108 | public int getDeviceOwnerUserId() { |
| 3109 | if (mService != null) { |
| 3110 | try { |
| 3111 | return mService.getDeviceOwnerUserId(); |
| 3112 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3113 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3114 | } |
| 3115 | } |
| 3116 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | /** |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3120 | * Clears the current device owner. The caller must be the device owner. |
| 3121 | * |
| 3122 | * This function should be used cautiously as once it is called it cannot |
| 3123 | * be undone. The device owner can only be set as a part of device setup |
| 3124 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3125 | * |
| 3126 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3127 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3128 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3129 | if (mService != null) { |
| 3130 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3131 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3132 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3133 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3138 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3139 | * Returns the device owner package name, only if it's running on the calling user. |
| 3140 | * |
| 3141 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3142 | * |
| 3143 | * @hide |
| 3144 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3145 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3146 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3147 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3148 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3152 | * @return true if the device is managed by any device owner. |
| 3153 | * |
| 3154 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3155 | * |
| 3156 | * @hide |
| 3157 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3158 | public boolean isDeviceManaged() { |
| 3159 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3160 | } |
| 3161 | |
| 3162 | /** |
| 3163 | * Returns the device owner name. Note this method *will* return the device owner |
| 3164 | * name when it's running on a different user. |
| 3165 | * |
| 3166 | * <p>Requires the MANAGE_USERS permission. |
| 3167 | * |
| 3168 | * @hide |
| 3169 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3170 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3171 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3172 | if (mService != null) { |
| 3173 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3174 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3175 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3176 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3177 | } |
| 3178 | } |
| 3179 | return null; |
| 3180 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3181 | |
| 3182 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3183 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3184 | * @deprecated Do not use |
| 3185 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3186 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3187 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3188 | @SystemApi |
| 3189 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3190 | return null; |
| 3191 | } |
| 3192 | |
| 3193 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3194 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3195 | * @deprecated Do not use |
| 3196 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3197 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3198 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3199 | @SystemApi |
| 3200 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3201 | return null; |
| 3202 | } |
| 3203 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3204 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3205 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3206 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3207 | * Sets the given component as an active admin and registers the package as the profile |
| 3208 | * owner for this user. The package must already be installed and there shouldn't be |
| 3209 | * an existing profile owner registered for this user. Also, this method must be called |
| 3210 | * before the user setup has been completed. |
| 3211 | * <p> |
| 3212 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3213 | * MANAGE_DEVICE_ADMINS permission. |
| 3214 | * @param admin The component to register as an active admin and profile owner. |
| 3215 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3216 | * @return whether the admin was successfully registered as the profile owner. |
| 3217 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3218 | * the user has already been set up. |
| 3219 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3220 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3221 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3222 | throws IllegalArgumentException { |
| 3223 | if (mService != null) { |
| 3224 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3225 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3226 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3227 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3228 | } catch (RemoteException re) { |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3229 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3230 | } |
| 3231 | } |
| 3232 | return false; |
| 3233 | } |
| 3234 | |
| 3235 | /** |
| 3236 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3237 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 3238 | * be from the same package as the active profile owner for this user, otherwise a |
| 3239 | * SecurityException will be thrown. |
| 3240 | * |
| 3241 | * @param admin The component to remove as the profile owner. |
| 3242 | * @return |
| 3243 | */ |
| 3244 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3245 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3246 | if (mService != null) { |
| 3247 | try { |
| 3248 | mService.clearProfileOwner(admin); |
| 3249 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3250 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3251 | } |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3256 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3257 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3258 | */ |
| 3259 | public boolean hasUserSetupCompleted() { |
| 3260 | if (mService != null) { |
| 3261 | try { |
| 3262 | return mService.hasUserSetupCompleted(); |
| 3263 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3264 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3265 | } |
| 3266 | } |
| 3267 | return true; |
| 3268 | } |
| 3269 | |
| 3270 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3271 | * @hide |
| 3272 | * 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] | 3273 | * already be installed. There must not already be a profile owner for this user. |
| 3274 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3275 | * this method. |
| 3276 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3277 | * - the caller is SYSTEM_UID. |
| 3278 | * - 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] | 3279 | * @param admin the component name to be registered as profile owner. |
| 3280 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3281 | * @param userHandle the userId to set the profile owner for. |
| 3282 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3283 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3284 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3285 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3286 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3287 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3288 | if (mService != null) { |
| 3289 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3290 | if (ownerName == null) { |
| 3291 | ownerName = ""; |
| 3292 | } |
| 3293 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3294 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3295 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3296 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3297 | } |
| 3298 | } |
| 3299 | return false; |
| 3300 | } |
| 3301 | |
| 3302 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3303 | * Sets the device owner information to be shown on the lock screen. |
| 3304 | * |
| 3305 | * <p>If the device owner information is {@code null} or empty then the device owner info is |
| 3306 | * 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] | 3307 | * <p>If the device owner information contains only whitespaces then the message on the lock |
| 3308 | * 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] | 3309 | * |
| 3310 | * @param admin The name of the admin component to check. |
| 3311 | * @param info Device owner information which will be displayed instead of the user |
| 3312 | * owner info. |
| 3313 | * @return Whether the device owner information has been set. |
| 3314 | */ |
| 3315 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3316 | if (mService != null) { |
| 3317 | try { |
| 3318 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3319 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3320 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | return false; |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * @return The device owner information. If it is not set returns {@code null}. |
| 3328 | */ |
| 3329 | public String getDeviceOwnerLockScreenInfo() { |
| 3330 | if (mService != null) { |
| 3331 | try { |
| 3332 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3333 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3334 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3335 | } |
| 3336 | } |
| 3337 | return null; |
| 3338 | } |
| 3339 | |
| 3340 | /** |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3341 | * Called by device or profile owners for setting the package suspended for this user. |
| 3342 | * A suspended package will not be started by the package manager, its notifications will |
| 3343 | * be hidden and it will not show up in recents. The package must already be installed. |
| 3344 | * |
| 3345 | * @param admin The name of the admin component to check. |
| 3346 | * @param packageName The package name of the app to suspend or unsuspend. |
| 3347 | * @param suspended If set to {@code true} than the package will be suspended, if set to |
| 3348 | * {@code false} the package will be unsuspended. |
| 3349 | * @return boolean {@code true} if the operation was successfully performed, {@code false} |
| 3350 | * otherwise. |
| 3351 | */ |
| 3352 | public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName, |
| 3353 | boolean suspended) { |
| 3354 | if (mService != null) { |
| 3355 | try { |
| 3356 | return mService.setPackageSuspended(admin, packageName, suspended); |
| 3357 | } catch (RemoteException re) { |
| 3358 | Log.w(TAG, "Failed talking with device policy service", re); |
| 3359 | } |
| 3360 | } |
| 3361 | return false; |
| 3362 | } |
| 3363 | |
| 3364 | /** |
| 3365 | * Called by device or profile owners to determine if a package is suspended. |
| 3366 | * |
| 3367 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3368 | * @param packageName The name of the package to retrieve the suspended status of. |
| 3369 | * @return boolean {@code true} if the package is suspended, {@code false} otherwise. |
| 3370 | */ |
| 3371 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3372 | if (mService != null) { |
| 3373 | try { |
| 3374 | return mService.getPackageSuspended(admin, packageName); |
| 3375 | } catch (RemoteException e) { |
| 3376 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3377 | } |
| 3378 | } |
| 3379 | return false; |
| 3380 | } |
| 3381 | |
| 3382 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3383 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3384 | * be used. Only the profile owner can call this. |
| 3385 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3386 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3387 | * |
| 3388 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3389 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3390 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3391 | if (mService != null) { |
| 3392 | try { |
| 3393 | mService.setProfileEnabled(admin); |
| 3394 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3395 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3396 | } |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3401 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3402 | * 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] | 3403 | * never called by the profile or device owner, the name will be set to default values. |
| 3404 | * |
| 3405 | * @see #isProfileOwnerApp |
| 3406 | * @see #isDeviceOwnerApp |
| 3407 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3408 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3409 | * @param profileName The name of the profile. |
| 3410 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3411 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3412 | if (mService != null) { |
| 3413 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3414 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3415 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3416 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3417 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3418 | } |
| 3419 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3420 | |
| 3421 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3422 | * 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] | 3423 | * 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] | 3424 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3425 | * |
| 3426 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3427 | * @return Whether or not the package is registered as the profile owner. |
| 3428 | */ |
| 3429 | public boolean isProfileOwnerApp(String packageName) { |
| 3430 | if (mService != null) { |
| 3431 | try { |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3432 | ComponentName profileOwner = mService.getProfileOwner( |
| 3433 | Process.myUserHandle().getIdentifier()); |
| 3434 | return profileOwner != null |
| 3435 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3436 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3437 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3438 | } |
| 3439 | } |
| 3440 | return false; |
| 3441 | } |
| 3442 | |
| 3443 | /** |
| 3444 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3445 | * @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] | 3446 | * owner has been set for that user. |
| 3447 | * @throws IllegalArgumentException if the userId is invalid. |
| 3448 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3449 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3450 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3451 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3452 | } |
| 3453 | |
| 3454 | /** |
| 3455 | * @see #getProfileOwner() |
| 3456 | * @hide |
| 3457 | */ |
| 3458 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3459 | if (mService != null) { |
| 3460 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3461 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3462 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3463 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3464 | throw new IllegalArgumentException( |
| 3465 | "Requested profile owner for invalid userId", re); |
| 3466 | } |
| 3467 | } |
| 3468 | return null; |
| 3469 | } |
| 3470 | |
| 3471 | /** |
| 3472 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3473 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3474 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3475 | * @throws IllegalArgumentException if the userId is invalid. |
| 3476 | */ |
| 3477 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3478 | if (mService != null) { |
| 3479 | try { |
| 3480 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3481 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3482 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3483 | throw new IllegalArgumentException( |
| 3484 | "Requested profile owner for invalid userId", re); |
| 3485 | } |
| 3486 | } |
| 3487 | return null; |
| 3488 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3489 | |
| 3490 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3491 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3492 | * @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] | 3493 | * @return the human readable name of the organisation associated with this profile owner or |
| 3494 | * null if one is not set. |
| 3495 | * @throws IllegalArgumentException if the userId is invalid. |
| 3496 | */ |
| 3497 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3498 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3499 | if (mService != null) { |
| 3500 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3501 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3502 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3503 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3504 | throw new IllegalArgumentException( |
| 3505 | "Requested profile owner for invalid userId", re); |
| 3506 | } |
| 3507 | } |
| 3508 | return null; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3512 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3513 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3514 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3515 | * the intent preferences are reset. |
| 3516 | * |
| 3517 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3518 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3519 | * intent handler for the filter. |
| 3520 | * |
| 3521 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3522 | * security exception will be thrown. |
| 3523 | * |
| 3524 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3525 | * @param filter The IntentFilter for which a default handler is added. |
| 3526 | * @param activity The Activity that is added as default intent handler. |
| 3527 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3528 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3529 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3530 | if (mService != null) { |
| 3531 | try { |
| 3532 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3533 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3534 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3535 | } |
| 3536 | } |
| 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * 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] | 3541 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3542 | * |
| 3543 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3544 | * exception will be thrown. |
| 3545 | * |
| 3546 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3547 | * @param packageName The name of the package for which preferences are removed. |
| 3548 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3549 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3550 | String packageName) { |
| 3551 | if (mService != null) { |
| 3552 | try { |
| 3553 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3554 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3555 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3556 | } |
| 3557 | } |
| 3558 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3559 | |
| 3560 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3561 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 3562 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 3563 | * {@link #getApplicationRestrictions}. |
| 3564 | * <p> |
| 3565 | * This permission is persistent until it is later cleared by calling this method with a |
| 3566 | * {@code null} value or uninstalling the managing package. |
| 3567 | * |
| 3568 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3569 | * @param packageName The package name which will be given access to application restrictions |
| 3570 | * APIs. If {@code null} is given the current package will be cleared. |
| 3571 | */ |
| 3572 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
| 3573 | @Nullable String packageName) { |
| 3574 | if (mService != null) { |
| 3575 | try { |
| 3576 | mService.setApplicationRestrictionsManagingPackage(admin, packageName); |
| 3577 | } catch (RemoteException e) { |
| 3578 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3579 | } |
| 3580 | } |
| 3581 | } |
| 3582 | |
| 3583 | /** |
| 3584 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 3585 | * package for the current user, or {@code null} if none is set. |
| 3586 | * |
| 3587 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3588 | * @return The package name allowed to manage application restrictions on the current user, or |
| 3589 | * {@code null} if none is set. |
| 3590 | */ |
| 3591 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 3592 | if (mService != null) { |
| 3593 | try { |
| 3594 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 3595 | } catch (RemoteException e) { |
| 3596 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3597 | } |
| 3598 | } |
| 3599 | return null; |
| 3600 | } |
| 3601 | |
| 3602 | /** |
| 3603 | * Returns {@code true} if the calling package has been granted permission via |
| 3604 | * {@link #setApplicationRestrictionsManagingPackage} to manage application |
| 3605 | * restrictions for the calling user. |
| 3606 | */ |
| 3607 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 3608 | if (mService != null) { |
| 3609 | try { |
| 3610 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 3611 | } catch (RemoteException e) { |
| 3612 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3613 | } |
| 3614 | } |
| 3615 | return false; |
| 3616 | } |
| 3617 | |
| 3618 | /** |
| 3619 | * Sets the application restrictions for a given target application running in the calling user. |
| 3620 | * |
| 3621 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 3622 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 3623 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3624 | * |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 3625 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
| 3626 | * <ul> |
| 3627 | * <li>{@code boolean} |
| 3628 | * <li>{@code int} |
| 3629 | * <li>{@code String} or {@code String[]} |
| 3630 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 3631 | * </ul> |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3632 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3633 | * <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] | 3634 | * the caller can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3635 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 3636 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3637 | * <p>The application restrictions are only made visible to the target application via |
| 3638 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or |
| 3639 | * device owner, and the application restrictions managing package via |
| 3640 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3641 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3642 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3643 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3644 | * @param packageName The name of the package to update restricted settings for. |
| 3645 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 3646 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3647 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3648 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3649 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3650 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3651 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3652 | Bundle settings) { |
| 3653 | if (mService != null) { |
| 3654 | try { |
| 3655 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3656 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3657 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3658 | } |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3663 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3664 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3665 | * trust agents but those enabled by this function call. If flag |
| 3666 | * {@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] | 3667 | * |
| 3668 | * <p>The calling device admin must have requested |
| 3669 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3670 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3671 | * |
| 3672 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3673 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3674 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3675 | * will be strictly disabled according to the state of the |
| 3676 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 3677 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 3678 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 3679 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3680 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3681 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 3682 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3683 | if (mService != null) { |
| 3684 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3685 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3686 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3687 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3688 | } |
| 3689 | } |
| 3690 | } |
| 3691 | |
| 3692 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3693 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 3694 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 3695 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3696 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3697 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3698 | * this function returns a list of configurations for all admins that declare |
| 3699 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 3700 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 3701 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 3702 | * 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] | 3703 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3704 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3705 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3706 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3707 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3708 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3712 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3713 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3714 | if (mService != null) { |
| 3715 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3716 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3717 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3718 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3719 | } |
| 3720 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3721 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3725 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 3726 | * 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] | 3727 | * |
| 3728 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3729 | * security exception will be thrown. |
| 3730 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3731 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3732 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 3733 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3734 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3735 | if (mService != null) { |
| 3736 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3737 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3738 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3739 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3745 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 3746 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3747 | * |
| 3748 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3749 | * security exception will be thrown. |
| 3750 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3751 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3752 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3753 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3754 | if (mService != null) { |
| 3755 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3756 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3757 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3758 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | return false; |
| 3762 | } |
| 3763 | |
| 3764 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3765 | * Determine whether or not caller-Id information has been disabled. |
| 3766 | * |
| 3767 | * @param userHandle The user for whom to check the caller-id permission |
| 3768 | * @hide |
| 3769 | */ |
| 3770 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 3771 | if (mService != null) { |
| 3772 | try { |
| 3773 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 3774 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3775 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3776 | } |
| 3777 | } |
| 3778 | return false; |
| 3779 | } |
| 3780 | |
| 3781 | /** |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 3782 | * Called by a profile owner of a managed profile to set whether contacts search from |
| 3783 | * the managed profile will be shown in the parent profile, for incoming calls. |
| 3784 | * |
| 3785 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3786 | * security exception will be thrown. |
| 3787 | * |
| 3788 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3789 | * @param disabled If true contacts search in the managed profile is not displayed. |
| 3790 | */ |
| 3791 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 3792 | boolean disabled) { |
| 3793 | if (mService != null) { |
| 3794 | try { |
| 3795 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 3796 | } catch (RemoteException e) { |
| 3797 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3798 | } |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | /** |
| 3803 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 3804 | * has been disabled. |
| 3805 | * |
| 3806 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3807 | * security exception will be thrown. |
| 3808 | * |
| 3809 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3810 | */ |
| 3811 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 3812 | if (mService != null) { |
| 3813 | try { |
| 3814 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 3815 | } catch (RemoteException e) { |
| 3816 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3817 | } |
| 3818 | } |
| 3819 | return false; |
| 3820 | } |
| 3821 | |
| 3822 | |
| 3823 | /** |
| 3824 | * Determine whether or not contacts search has been disabled. |
| 3825 | * |
| 3826 | * @param userHandle The user for whom to check the contacts search permission |
| 3827 | * @hide |
| 3828 | */ |
| 3829 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 3830 | if (mService != null) { |
| 3831 | try { |
| 3832 | return mService |
| 3833 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 3834 | } catch (RemoteException e) { |
| 3835 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3836 | } |
| 3837 | } |
| 3838 | return false; |
| 3839 | } |
| 3840 | |
| 3841 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3842 | * 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] | 3843 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3844 | * @hide |
| 3845 | */ |
| 3846 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3847 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3848 | if (mService != null) { |
| 3849 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3850 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 3851 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3852 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3853 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3854 | } |
| 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3859 | * 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] | 3860 | * @hide |
| 3861 | */ |
| 3862 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 3863 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3864 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 3865 | originalIntent); |
| 3866 | } |
| 3867 | |
| 3868 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3869 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 3870 | * devices can access enterprise contacts. |
| 3871 | * <p> |
| 3872 | * The calling device admin must be a profile owner. If it is not, a |
| 3873 | * security exception will be thrown. |
| 3874 | * <p> |
| 3875 | * This API works on managed profile only. |
| 3876 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3877 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3878 | * with. |
| 3879 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 3880 | * contacts. |
| 3881 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3882 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3883 | if (mService != null) { |
| 3884 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3885 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3886 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3887 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3888 | } |
| 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | /** |
| 3893 | * Called by a profile owner of a managed profile to determine whether or |
| 3894 | * not Bluetooth devices cannot access enterprise contacts. |
| 3895 | * <p> |
| 3896 | * The calling device admin must be a profile owner. If it is not, a |
| 3897 | * security exception will be thrown. |
| 3898 | * <p> |
| 3899 | * This API works on managed profile only. |
| 3900 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3901 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3902 | * with. |
| 3903 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3904 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3905 | if (mService != null) { |
| 3906 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3907 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3908 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3909 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | return true; |
| 3913 | } |
| 3914 | |
| 3915 | /** |
| 3916 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 3917 | * <p> |
| 3918 | * This API works on managed profile UserHandle only. |
| 3919 | * |
| 3920 | * @param userHandle The user for whom to check the caller-id permission |
| 3921 | * @hide |
| 3922 | */ |
| 3923 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 3924 | if (mService != null) { |
| 3925 | try { |
| 3926 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 3927 | .getIdentifier()); |
| 3928 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3929 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3930 | } |
| 3931 | } |
| 3932 | return true; |
| 3933 | } |
| 3934 | |
| 3935 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3936 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 3937 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 3938 | * Only activity intents are supported. |
| 3939 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3940 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3941 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 3942 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 3943 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 3944 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3945 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3946 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3947 | if (mService != null) { |
| 3948 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3949 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3950 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3951 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | } |
| 3955 | |
| 3956 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3957 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 3958 | * 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] | 3959 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3960 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3961 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3962 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3963 | if (mService != null) { |
| 3964 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3965 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3966 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3967 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3968 | } |
| 3969 | } |
| 3970 | } |
| 3971 | |
| 3972 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3973 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 3974 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 3975 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 3976 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3977 | * By default the user can use any accessiblity service. When zero or more packages have |
| 3978 | * 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] | 3979 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3980 | * |
| 3981 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 3982 | * can be used, calling with an empty list only allows the builtin system's services. |
| 3983 | * |
| 3984 | * <p> System accesibility services are always available to the user the list can't modify |
| 3985 | * this. |
| 3986 | * |
| 3987 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3988 | * @param packageNames List of accessibility service package names. |
| 3989 | * |
| 3990 | * @return true if setting the restriction succeeded. It fail if there is |
| 3991 | * one or more non-system accessibility services enabled, that are not in the list. |
| 3992 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3993 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3994 | List<String> packageNames) { |
| 3995 | if (mService != null) { |
| 3996 | try { |
| 3997 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 3998 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3999 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4000 | } |
| 4001 | } |
| 4002 | return false; |
| 4003 | } |
| 4004 | |
| 4005 | /** |
| 4006 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 4007 | * |
| 4008 | * <p>An empty list means no accessibility services except system services are allowed. |
| 4009 | * Null means all accessibility services are allowed. |
| 4010 | * |
| 4011 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4012 | * @return List of accessiblity service package names. |
| 4013 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4014 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4015 | if (mService != null) { |
| 4016 | try { |
| 4017 | return mService.getPermittedAccessibilityServices(admin); |
| 4018 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4019 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4020 | } |
| 4021 | } |
| 4022 | return null; |
| 4023 | } |
| 4024 | |
| 4025 | /** |
| 4026 | * Returns the list of accessibility services permitted by the device or profiles |
| 4027 | * owners of this user. |
| 4028 | * |
| 4029 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4030 | * it will contain the intersection of the permitted lists for any device or profile |
| 4031 | * owners that apply to this user. It will also include any system accessibility services. |
| 4032 | * |
| 4033 | * @param userId which user to check for. |
| 4034 | * @return List of accessiblity service package names. |
| 4035 | * @hide |
| 4036 | */ |
| 4037 | @SystemApi |
| 4038 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4039 | if (mService != null) { |
| 4040 | try { |
| 4041 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4042 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4043 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4044 | } |
| 4045 | } |
| 4046 | return null; |
| 4047 | } |
| 4048 | |
| 4049 | /** |
| 4050 | * Called by a profile or device owner to set the permitted input methods services. When |
| 4051 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4052 | * user the device owner or profile owner is an admin for. |
| 4053 | * |
| 4054 | * By default the user can use any input method. When zero or more packages have |
| 4055 | * been added, input method that are not in the list and not part of the system |
| 4056 | * can not be enabled by the user. |
| 4057 | * |
| 4058 | * This method will fail if it is called for a admin that is not for the foreground user |
| 4059 | * or a profile of the foreground user. |
| 4060 | * |
| 4061 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 4062 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 4063 | * |
| 4064 | * <p> System input methods are always available to the user this method can't modify this. |
| 4065 | * |
| 4066 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4067 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 4068 | * @return true if setting the restriction succeeded. It will fail if there are |
| 4069 | * one or more non-system input methods currently enabled that are not in |
| 4070 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4071 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4072 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4073 | if (mService != null) { |
| 4074 | try { |
| 4075 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4076 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4077 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4078 | } |
| 4079 | } |
| 4080 | return false; |
| 4081 | } |
| 4082 | |
| 4083 | |
| 4084 | /** |
| 4085 | * Returns the list of permitted input methods set by this device or profile owner. |
| 4086 | * |
| 4087 | * <p>An empty list means no input methods except system input methods are allowed. |
| 4088 | * Null means all input methods are allowed. |
| 4089 | * |
| 4090 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4091 | * @return List of input method package names. |
| 4092 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4093 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4094 | if (mService != null) { |
| 4095 | try { |
| 4096 | return mService.getPermittedInputMethods(admin); |
| 4097 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4098 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4099 | } |
| 4100 | } |
| 4101 | return null; |
| 4102 | } |
| 4103 | |
| 4104 | /** |
| 4105 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4106 | * 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] | 4107 | * |
| 4108 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4109 | * it will contain the intersection of the permitted lists for any device or profile |
| 4110 | * owners that apply to this user. It will also include any system input methods. |
| 4111 | * |
| 4112 | * @return List of input method package names. |
| 4113 | * @hide |
| 4114 | */ |
| 4115 | @SystemApi |
| 4116 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4117 | if (mService != null) { |
| 4118 | try { |
| 4119 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4120 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4121 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4122 | } |
| 4123 | } |
| 4124 | return null; |
| 4125 | } |
| 4126 | |
| 4127 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4128 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4129 | * currently installed it. |
| 4130 | * |
| 4131 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4132 | * |
| 4133 | * @return List of package names to keep cached. |
| 4134 | * @hide |
| 4135 | */ |
| 4136 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4137 | if (mService != null) { |
| 4138 | try { |
| 4139 | return mService.getKeepUninstalledPackages(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); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | return null; |
| 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4149 | * currently installed it. |
| 4150 | * |
| 4151 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4152 | * automatically pre-cached.</p> |
| 4153 | * |
| 4154 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4155 | * @param packageNames List of package names to keep cached. |
| 4156 | * @hide |
| 4157 | */ |
| 4158 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4159 | @NonNull List<String> packageNames) { |
| 4160 | if (mService != null) { |
| 4161 | try { |
| 4162 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4163 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4164 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4170 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4171 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4172 | * created. If you need to persist an identifier for this user, use |
| 4173 | * {@link UserManager#getSerialNumberForUser}. |
| 4174 | * |
| 4175 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4176 | * @param name the user's name |
| 4177 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4178 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4179 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4180 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4181 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4182 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4183 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4184 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4185 | try { |
| 4186 | return mService.createUser(admin, name); |
| 4187 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4188 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4189 | } |
| 4190 | return null; |
| 4191 | } |
| 4192 | |
| 4193 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4194 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4195 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4196 | * created. If you need to persist an identifier for this user, use |
| 4197 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4198 | * immediately. |
| 4199 | * |
| 4200 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4201 | * as registered as an active admin on the new user. The profile owner package will be |
| 4202 | * installed on the new user if it already is installed on the device. |
| 4203 | * |
| 4204 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4205 | * profileOwnerComponent when onEnable is called. |
| 4206 | * |
| 4207 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4208 | * @param name the user's name |
| 4209 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4210 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4211 | * the user. |
| 4212 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4213 | * on the new user. |
| 4214 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4215 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4216 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4217 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4218 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4219 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4220 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4221 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4222 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4223 | try { |
| 4224 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 4225 | adminExtras); |
| 4226 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4227 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4228 | } |
| 4229 | return null; |
| 4230 | } |
| 4231 | |
| 4232 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4233 | * 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] | 4234 | */ |
| 4235 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4236 | |
| 4237 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4238 | * Called by a device owner to create a user with the specified name and a given component of |
| 4239 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4240 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4241 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4242 | * user will not be started in the background. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4243 | * |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4244 | * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also |
| 4245 | * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and |
| 4246 | * will be registered as an active admin on the new user. The profile owner package will be |
| 4247 | * installed on the new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4248 | * |
| 4249 | * <p>If the adminExtras are not null, they will be stored on the device until the user is |
| 4250 | * started for the first time. Then the extras will be passed to the admin when |
| 4251 | * onEnable is called. |
| 4252 | * |
| 4253 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4254 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4255 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
| 4256 | * same package as admin, otherwise no user is created and an IllegalArgumentException is |
| 4257 | * thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4258 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
| 4259 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4260 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4261 | * @see UserHandle |
| 4262 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4263 | * user could not be created. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4264 | */ |
| 4265 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4266 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4267 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4268 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4269 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4270 | } catch (RemoteException re) { |
| 4271 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 4272 | } |
| 4273 | return null; |
| 4274 | } |
| 4275 | |
| 4276 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4277 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 4278 | * not be removed. |
| 4279 | * |
| 4280 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4281 | * @param userHandle the user to remove. |
| 4282 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 4283 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4284 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4285 | try { |
| 4286 | return mService.removeUser(admin, userHandle); |
| 4287 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4288 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4289 | return false; |
| 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4294 | * Called by a device owner to switch the specified user to the foreground. |
| 4295 | * |
| 4296 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4297 | * @param userHandle the user to switch to; null will switch to primary. |
| 4298 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 4299 | * |
| 4300 | * @see Intent#ACTION_USER_FOREGROUND |
| 4301 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4302 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4303 | try { |
| 4304 | return mService.switchUser(admin, userHandle); |
| 4305 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4306 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4307 | return false; |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4312 | * Retrieves the application restrictions for a given target application running in the calling |
| 4313 | * user. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4314 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4315 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4316 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4317 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4318 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4319 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4320 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4321 | * @param packageName The name of the package to fetch restricted settings of. |
| 4322 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 4323 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 4324 | * if no restrictions have been set. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4325 | * |
| 4326 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4327 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4328 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4329 | if (mService != null) { |
| 4330 | try { |
| 4331 | return mService.getApplicationRestrictions(admin, packageName); |
| 4332 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4333 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | return null; |
| 4337 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4338 | |
| 4339 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4340 | * 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] | 4341 | * <p> |
| 4342 | * The calling device admin must be a profile or device owner; if it is not, |
| 4343 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4344 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4345 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4346 | * with. |
| 4347 | * @param key The key of the restriction. See the constants in |
| 4348 | * {@link android.os.UserManager} for the list of keys. |
| 4349 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4350 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4351 | if (mService != null) { |
| 4352 | try { |
| 4353 | mService.setUserRestriction(admin, key, true); |
| 4354 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4355 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4356 | } |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4361 | * 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] | 4362 | * <p> |
| 4363 | * The calling device admin must be a profile or device owner; if it is not, |
| 4364 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4365 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4366 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4367 | * with. |
| 4368 | * @param key The key of the restriction. See the constants in |
| 4369 | * {@link android.os.UserManager} for the list of keys. |
| 4370 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4371 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4372 | if (mService != null) { |
| 4373 | try { |
| 4374 | mService.setUserRestriction(admin, key, false); |
| 4375 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4376 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4377 | } |
| 4378 | } |
| 4379 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4380 | |
| 4381 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4382 | * Called by a profile or device owner to get user restrictions set with |
| 4383 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4384 | * <p> |
| 4385 | * The target user may have more restrictions set by the system or other device owner / profile |
| 4386 | * owner. To get all the user restrictions currently set, use |
| 4387 | * {@link UserManager#getUserRestrictions()}. |
| 4388 | * |
| 4389 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4390 | * @throws SecurityException if the {@code admin} is not an active admin. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4391 | */ |
| 4392 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4393 | return getUserRestrictions(admin, myUserId()); |
| 4394 | } |
| 4395 | |
| 4396 | /** @hide per-user version */ |
| 4397 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4398 | Bundle ret = null; |
| 4399 | if (mService != null) { |
| 4400 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4401 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4402 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4403 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4404 | } |
| 4405 | } |
| 4406 | return ret == null ? new Bundle() : ret; |
| 4407 | } |
| 4408 | |
| 4409 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4410 | * 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] | 4411 | * is unavailable for use, but the data and actual package file remain. |
| 4412 | * |
| 4413 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4414 | * @param packageName The name of the package to hide or unhide. |
| 4415 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 4416 | * unhidden. |
| 4417 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4418 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4419 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4420 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4421 | if (mService != null) { |
| 4422 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4423 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4424 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4425 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4426 | } |
| 4427 | } |
| 4428 | return false; |
| 4429 | } |
| 4430 | |
| 4431 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4432 | * 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] | 4433 | * |
| 4434 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4435 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4436 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4437 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4438 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4439 | if (mService != null) { |
| 4440 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4441 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4442 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4443 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4444 | } |
| 4445 | } |
| 4446 | return false; |
| 4447 | } |
| 4448 | |
| 4449 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4450 | * 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] | 4451 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4452 | * |
| 4453 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4454 | * @param packageName The package to be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4455 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4456 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4457 | if (mService != null) { |
| 4458 | try { |
| 4459 | mService.enableSystemApp(admin, packageName); |
| 4460 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4461 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4462 | } |
| 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4467 | * 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] | 4468 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4469 | * |
| 4470 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4471 | * @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] | 4472 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4473 | * @return int The number of activities that matched the intent and were installed. |
| 4474 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4475 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4476 | if (mService != null) { |
| 4477 | try { |
| 4478 | return mService.enableSystemAppWithIntent(admin, intent); |
| 4479 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4480 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | return 0; |
| 4484 | } |
| 4485 | |
| 4486 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4487 | * Called by a device owner or profile owner to disable account management for a specific type |
| 4488 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4489 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4490 | * <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] | 4491 | * security exception will be thrown. |
| 4492 | * |
| 4493 | * <p>When account management is disabled for an account type, adding or removing an account |
| 4494 | * of that type will not be possible. |
| 4495 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 4496 | * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
| 4497 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 4498 | * management for a specific type is disabled. |
| 4499 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4500 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4501 | * @param accountType For which account management is disabled or enabled. |
| 4502 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 4503 | * enabled (false). |
| 4504 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4505 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4506 | boolean disabled) { |
| 4507 | if (mService != null) { |
| 4508 | try { |
| 4509 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 4510 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4511 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4517 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 4518 | * |
| 4519 | * <p> Account management can be disabled/enabled by calling |
| 4520 | * {@link #setAccountManagementDisabled}. |
| 4521 | * |
| 4522 | * @return a list of account types for which account management has been disabled. |
| 4523 | * |
| 4524 | * @see #setAccountManagementDisabled |
| 4525 | */ |
| 4526 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4527 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4528 | } |
| 4529 | |
| 4530 | /** |
| 4531 | * @see #getAccountTypesWithManagementDisabled() |
| 4532 | * @hide |
| 4533 | */ |
| 4534 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4535 | if (mService != null) { |
| 4536 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4537 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4538 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4539 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4540 | } |
| 4541 | } |
| 4542 | |
| 4543 | return null; |
| 4544 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4545 | |
| 4546 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4547 | * Sets which packages may enter lock task mode. |
| 4548 | * |
| 4549 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 4550 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4551 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4552 | * 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] | 4553 | * package list results in locked tasks belonging to those packages to be finished. |
| 4554 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 4555 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4556 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4557 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4558 | * |
| 4559 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 4560 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 4561 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 4562 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4563 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4564 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4565 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4566 | if (mService != null) { |
| 4567 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4568 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4569 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4570 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4571 | } |
| 4572 | } |
| 4573 | } |
| 4574 | |
| 4575 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4576 | * 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] | 4577 | * |
| 4578 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4579 | * @hide |
| 4580 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4581 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4582 | if (mService != null) { |
| 4583 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4584 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4585 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4586 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | return null; |
| 4590 | } |
| 4591 | |
| 4592 | /** |
| 4593 | * This function lets the caller know whether the given component is allowed to start the |
| 4594 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4595 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4596 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4597 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4598 | if (mService != null) { |
| 4599 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4600 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4601 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4602 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4603 | } |
| 4604 | } |
| 4605 | return false; |
| 4606 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4607 | |
| 4608 | /** |
| 4609 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 4610 | * 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] | 4611 | * <p>The settings that can be updated with this method are: |
| 4612 | * <ul> |
| 4613 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 4614 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 4615 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4616 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4617 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4618 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 4619 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4620 | * 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] | 4621 | * 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] | 4622 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4623 | * 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] | 4624 | * </li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4625 | * </ul> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4626 | * <p>Changing the following settings has no effect as of |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4627 | * {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4628 | * <ul> |
| 4629 | * <li>{@link Settings.Global#BLUETOOTH_ON}. |
| 4630 | * Use {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 4631 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
| 4632 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 4633 | * <li>{@link Settings.Global#MODE_RINGER}. |
| 4634 | * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
| 4635 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 4636 | * <li>{@link Settings.Global#WIFI_ON}. |
| 4637 | * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
| 4638 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4639 | * |
| 4640 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4641 | * @param setting The name of the setting to update. |
| 4642 | * @param value The value to update the setting to. |
| 4643 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4644 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4645 | if (mService != null) { |
| 4646 | try { |
| 4647 | mService.setGlobalSetting(admin, setting, value); |
| 4648 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4649 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4650 | } |
| 4651 | } |
| 4652 | } |
| 4653 | |
| 4654 | /** |
| 4655 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 4656 | * that the value of the setting is in the correct form for the setting type should be performed |
| 4657 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4658 | * <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] | 4659 | * <ul> |
| 4660 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 4661 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4662 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 4663 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4664 | * <p>A device owner can additionally update the following settings: |
| 4665 | * <ul> |
| 4666 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 4667 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4668 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4669 | * @param setting The name of the setting to update. |
| 4670 | * @param value The value to update the setting to. |
| 4671 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4672 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4673 | if (mService != null) { |
| 4674 | try { |
| 4675 | mService.setSecureSetting(admin, setting, value); |
| 4676 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4677 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4678 | } |
| 4679 | } |
| 4680 | } |
| 4681 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4682 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4683 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4684 | * making permission requests of a local or remote administrator of the user. |
| 4685 | * <p/> |
| 4686 | * Only a profile owner can designate the restrictions provider. |
| 4687 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4688 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 4689 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4690 | * it removes the restrictions provider previously assigned. |
| 4691 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4692 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 4693 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4694 | if (mService != null) { |
| 4695 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4696 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4697 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4698 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4699 | } |
| 4700 | } |
| 4701 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4702 | |
| 4703 | /** |
| 4704 | * Called by profile or device owners to set the master volume mute on or off. |
| 4705 | * |
| 4706 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4707 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 4708 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4709 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4710 | if (mService != null) { |
| 4711 | try { |
| 4712 | mService.setMasterVolumeMuted(admin, on); |
| 4713 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4714 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | } |
| 4718 | |
| 4719 | /** |
| 4720 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 4721 | * |
| 4722 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4723 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 4724 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4725 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4726 | if (mService != null) { |
| 4727 | try { |
| 4728 | return mService.isMasterVolumeMuted(admin); |
| 4729 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4730 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4731 | } |
| 4732 | } |
| 4733 | return false; |
| 4734 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4735 | |
| 4736 | /** |
| 4737 | * Called by profile or device owners to change whether a user can uninstall |
| 4738 | * a package. |
| 4739 | * |
| 4740 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4741 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4742 | * @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] | 4743 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4744 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4745 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4746 | if (mService != null) { |
| 4747 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4748 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4749 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4750 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4751 | } |
| 4752 | } |
| 4753 | } |
| 4754 | |
| 4755 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4756 | * 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] | 4757 | * 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] | 4758 | * <p> |
| 4759 | * <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] | 4760 | * 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] | 4761 | * 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] | 4762 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4763 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4764 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 4765 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4766 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 4767 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4768 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4769 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4770 | if (mService != null) { |
| 4771 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 4772 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4773 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4774 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | return false; |
| 4778 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4779 | |
| 4780 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4781 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 4782 | * 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] | 4783 | * 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] | 4784 | * 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] | 4785 | * a package may have zero or more provider components, where each component |
| 4786 | * provides a different widget type. |
| 4787 | * <p> |
| 4788 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4789 | * |
| 4790 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4791 | * @param packageName The package from which widget providers are white-listed. |
| 4792 | * @return Whether the package was added. |
| 4793 | * |
| 4794 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4795 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4796 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4797 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4798 | if (mService != null) { |
| 4799 | try { |
| 4800 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 4801 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4802 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4803 | } |
| 4804 | } |
| 4805 | return false; |
| 4806 | } |
| 4807 | |
| 4808 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4809 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 4810 | * 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] | 4811 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 4812 | * android.content.ComponentName, String)}. |
| 4813 | * <p> |
| 4814 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4815 | * |
| 4816 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4817 | * @param packageName The package from which widget providers are no longer |
| 4818 | * white-listed. |
| 4819 | * @return Whether the package was removed. |
| 4820 | * |
| 4821 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4822 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4823 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4824 | public boolean removeCrossProfileWidgetProvider( |
| 4825 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4826 | if (mService != null) { |
| 4827 | try { |
| 4828 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 4829 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4830 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4831 | } |
| 4832 | } |
| 4833 | return false; |
| 4834 | } |
| 4835 | |
| 4836 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4837 | * 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] | 4838 | * available in the parent profile. |
| 4839 | * |
| 4840 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4841 | * @return The white-listed package list. |
| 4842 | * |
| 4843 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4844 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4845 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4846 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4847 | if (mService != null) { |
| 4848 | try { |
| 4849 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 4850 | if (providers != null) { |
| 4851 | return providers; |
| 4852 | } |
| 4853 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4854 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4855 | } |
| 4856 | } |
| 4857 | return Collections.emptyList(); |
| 4858 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4859 | |
| 4860 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4861 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4862 | * |
| 4863 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4864 | * @param icon the bitmap to set as the photo. |
| 4865 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4866 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4867 | try { |
| 4868 | mService.setUserIcon(admin, icon); |
| 4869 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4870 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4871 | } |
| 4872 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 4873 | |
| 4874 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4875 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 4876 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4877 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4878 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 4879 | * components in the device owner package can set system update policies and the |
| 4880 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4881 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4882 | * @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] | 4883 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4884 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4885 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4886 | if (mService != null) { |
| 4887 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4888 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4889 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4890 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4891 | } |
| 4892 | } |
| 4893 | } |
| 4894 | |
| 4895 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4896 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4897 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4898 | * @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] | 4899 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4900 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4901 | if (mService != null) { |
| 4902 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 4903 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4904 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4905 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | return null; |
| 4909 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4910 | |
| 4911 | /** |
| 4912 | * Called by a device owner to disable the keyguard altogether. |
| 4913 | * |
| 4914 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 4915 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 4916 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 4917 | * being disabled. |
| 4918 | * |
| 4919 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4920 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4921 | * |
| 4922 | * @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] | 4923 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4924 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4925 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4926 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4927 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4928 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4929 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4930 | return false; |
| 4931 | } |
| 4932 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4933 | |
| 4934 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4935 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 4936 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4937 | * a single use device. |
| 4938 | * |
| 4939 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4940 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 4941 | * |
| 4942 | * @return {@code false} if attempting to disable the status bar failed. |
| 4943 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4944 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4945 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4946 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4947 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4948 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4949 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4950 | return false; |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4951 | } |
| 4952 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 4953 | |
| 4954 | /** |
| 4955 | * Callable by the system update service to notify device owners about pending updates. |
| 4956 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 4957 | * permission. |
| 4958 | * |
| 4959 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 4960 | * when the current pending update was first available. -1 if no update is available. |
| 4961 | * @hide |
| 4962 | */ |
| 4963 | @SystemApi |
| 4964 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 4965 | if (mService != null) { |
| 4966 | try { |
| 4967 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 4968 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4969 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 4970 | } |
| 4971 | } |
| 4972 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 4973 | |
| 4974 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4975 | * Called by profile or device owners to set the default response for future runtime permission |
| 4976 | * requests by applications. The policy can allow for normal operation which prompts the |
| 4977 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 4978 | * 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] | 4979 | * updates. When a permission is denied or granted this way, the effect is equivalent to setting |
| 4980 | * the permission grant state via {@link #setPermissionGrantState}. |
| 4981 | * |
| 4982 | * <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] | 4983 | * 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] | 4984 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4985 | * @param admin Which profile or device owner this request is associated with. |
| 4986 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 4987 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 4988 | * |
| 4989 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4990 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4991 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4992 | try { |
| 4993 | mService.setPermissionPolicy(admin, policy); |
| 4994 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4995 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4996 | } |
| 4997 | } |
| 4998 | |
| 4999 | /** |
| 5000 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5001 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5002 | * @param admin Which profile or device owner this request is associated with. |
| 5003 | * @return the current policy for future permission requests. |
| 5004 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5005 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5006 | try { |
| 5007 | return mService.getPermissionPolicy(admin); |
| 5008 | } catch (RemoteException re) { |
| 5009 | return PERMISSION_POLICY_PROMPT; |
| 5010 | } |
| 5011 | } |
| 5012 | |
| 5013 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5014 | * Sets the grant state of a runtime permission for a specific application. The state |
| 5015 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 5016 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 5017 | * is denied and the user cannot manage it through the UI, and {@link |
| 5018 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 5019 | * user cannot manage it through the UI. This might affect all permissions in a |
| 5020 | * group that the runtime permission belongs to. This method can only be called |
| 5021 | * by a profile or device owner. |
| 5022 | * |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5023 | * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not |
| 5024 | * revoke the permission. It retains the previous grant, if any. |
| 5025 | * |
| 5026 | * <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] | 5027 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5028 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5029 | * @param admin Which profile or device owner this request is associated with. |
| 5030 | * @param packageName The application to grant or revoke a permission to. |
| 5031 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5032 | * @param grantState The permission grant state which is one of {@link |
| 5033 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5034 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5035 | * @return whether the permission was successfully granted or revoked. |
| 5036 | * |
| 5037 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5038 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5039 | * @see #PERMISSION_GRANT_STATE_GRANTED |
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 boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5042 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5043 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5044 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5045 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5046 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5047 | return false; |
| 5048 | } |
| 5049 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5050 | |
| 5051 | /** |
| 5052 | * Returns the current grant state of a runtime permission for a specific application. |
| 5053 | * |
| 5054 | * @param admin Which profile or device owner this request is associated with. |
| 5055 | * @param packageName The application to check the grant state for. |
| 5056 | * @param permission The permission to check for. |
| 5057 | * @return the current grant state specified by device policy. If the profile or device owner |
| 5058 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 5059 | * This does not indicate whether or not the permission is currently granted for the package. |
| 5060 | * |
| 5061 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 5062 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5063 | * which indicates if the permission is currently denied or granted. |
| 5064 | * |
| 5065 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5066 | * @see PackageManager#checkPermission(String, String) |
| 5067 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5068 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5069 | String permission) { |
| 5070 | try { |
| 5071 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5072 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5073 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5074 | return PERMISSION_GRANT_STATE_DEFAULT; |
| 5075 | } |
| 5076 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5077 | |
| 5078 | /** |
| 5079 | * Returns if provisioning a managed profile or device is possible or not. |
| 5080 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5081 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 5082 | * Note that even if this method returns true, there is a slight possibility that the |
| 5083 | * provisioning will not be allowed when it is actually initiated because some event has |
| 5084 | * happened in between. |
| 5085 | * @return if provisioning a managed profile or device is possible or not. |
| 5086 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5087 | */ |
| 5088 | public boolean isProvisioningAllowed(String action) { |
| 5089 | try { |
| 5090 | return mService.isProvisioningAllowed(action); |
| 5091 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5092 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5093 | return false; |
| 5094 | } |
| 5095 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5096 | |
| 5097 | /** |
| 5098 | * @hide |
| 5099 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5100 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5101 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5102 | * @param admin Which profile owner this request is associated with. |
| 5103 | * @return if this user is a managed profile of another user. |
| 5104 | */ |
| 5105 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5106 | try { |
| 5107 | return mService.isManagedProfile(admin); |
| 5108 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5109 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5110 | return false; |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | /** |
| 5115 | * @hide |
| 5116 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5117 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5118 | * @param admin Which device owner this request is associated with. |
| 5119 | * @return if this user is a system-only user. |
| 5120 | */ |
| 5121 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5122 | try { |
| 5123 | return mService.isSystemOnlyUser(admin); |
| 5124 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5125 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5126 | return false; |
| 5127 | } |
| 5128 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5129 | |
| 5130 | /** |
| 5131 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5132 | * |
| 5133 | * @return the MAC address of the Wi-Fi device, or null when the information is not |
| 5134 | * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5135 | * |
| 5136 | * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5137 | */ |
| 5138 | public String getWifiMacAddress() { |
| 5139 | try { |
| 5140 | return mService.getWifiMacAddress(); |
| 5141 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5142 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5143 | return null; |
| 5144 | } |
| 5145 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5146 | |
| 5147 | /** |
| 5148 | * Called by device owner to reboot the device. |
| 5149 | */ |
| 5150 | public void reboot(@NonNull ComponentName admin) { |
| 5151 | try { |
| 5152 | mService.reboot(admin); |
| 5153 | } catch (RemoteException re) { |
| 5154 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5155 | } |
| 5156 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5157 | |
| 5158 | /** |
| 5159 | * Called by a device admin to set the short support message. This will |
| 5160 | * be displayed to the user in settings screens where funtionality has |
| 5161 | * been disabled by the admin. |
| 5162 | * |
| 5163 | * The message should be limited to a short statement such as |
| 5164 | * "This setting is disabled by your administrator. Contact someone@example.com |
| 5165 | * for support." |
| 5166 | * If the message is longer than 200 characters it may be truncated. |
| 5167 | * |
| 5168 | * @see #setLongSupportMessage |
| 5169 | * |
| 5170 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5171 | * @param message Short message to be displayed to the user in settings or null to |
| 5172 | * clear the existing message. |
| 5173 | */ |
| 5174 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5175 | @Nullable String message) { |
| 5176 | if (mService != null) { |
| 5177 | try { |
| 5178 | mService.setShortSupportMessage(admin, message); |
| 5179 | } catch (RemoteException e) { |
| 5180 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5181 | } |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | /** |
| 5186 | * Called by a device admin to get the short support message. |
| 5187 | * |
| 5188 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5189 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5190 | * or null if no message has been set. |
| 5191 | */ |
| 5192 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5193 | if (mService != null) { |
| 5194 | try { |
| 5195 | return mService.getShortSupportMessage(admin); |
| 5196 | } catch (RemoteException e) { |
| 5197 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5198 | } |
| 5199 | } |
| 5200 | return null; |
| 5201 | } |
| 5202 | |
| 5203 | /** |
| 5204 | * Called by a device admin to set the long support message. This will |
| 5205 | * be displayed to the user in the device administators settings screen. |
| 5206 | * |
| 5207 | * @see #setShortSupportMessage |
| 5208 | * |
| 5209 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5210 | * @param message Long message to be displayed to the user in settings or null to |
| 5211 | * clear the existing message. |
| 5212 | */ |
| 5213 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5214 | @Nullable String message) { |
| 5215 | if (mService != null) { |
| 5216 | try { |
| 5217 | mService.setLongSupportMessage(admin, message); |
| 5218 | } catch (RemoteException e) { |
| 5219 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5220 | } |
| 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | /** |
| 5225 | * Called by a device admin to get the long support message. |
| 5226 | * |
| 5227 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5228 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5229 | * or null if no message has been set. |
| 5230 | */ |
| 5231 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5232 | if (mService != null) { |
| 5233 | try { |
| 5234 | return mService.getLongSupportMessage(admin); |
| 5235 | } catch (RemoteException e) { |
| 5236 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5237 | } |
| 5238 | } |
| 5239 | return null; |
| 5240 | } |
| 5241 | |
| 5242 | /** |
| 5243 | * Called by the system to get the short support message. |
| 5244 | * |
| 5245 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5246 | * @param userHandle user id the admin is running as. |
| 5247 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5248 | * |
| 5249 | * @hide |
| 5250 | */ |
| 5251 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5252 | if (mService != null) { |
| 5253 | try { |
| 5254 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5255 | } catch (RemoteException e) { |
| 5256 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5257 | } |
| 5258 | } |
| 5259 | return null; |
| 5260 | } |
| 5261 | |
| 5262 | |
| 5263 | /** |
| 5264 | * Called by the system to get the long support message. |
| 5265 | * |
| 5266 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5267 | * @param userHandle user id the admin is running as. |
| 5268 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5269 | * |
| 5270 | * @hide |
| 5271 | */ |
| 5272 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5273 | if (mService != null) { |
| 5274 | try { |
| 5275 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5276 | } catch (RemoteException e) { |
| 5277 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5278 | } |
| 5279 | } |
| 5280 | return null; |
| 5281 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5282 | |
| 5283 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5284 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5285 | * whose calls act on the parent profile. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5286 | * |
| 5287 | * <p> Note only some methods will work on the parent Manager. |
| 5288 | * |
| 5289 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
| 5290 | */ |
| 5291 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5292 | try { |
| 5293 | if (!mService.isManagedProfile(admin)) { |
| 5294 | throw new SecurityException("The current user does not have a parent profile."); |
| 5295 | } |
| 5296 | return new DevicePolicyManager(mContext, true); |
| 5297 | } catch (RemoteException re) { |
| 5298 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5299 | return null; |
| 5300 | } |
| 5301 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5302 | |
| 5303 | /** |
| 5304 | * Called by a profile owner of a managed profile to set the color used for customization. |
| 5305 | * This color is used as background color of the confirm credentials screen for that user. |
| 5306 | * The default color is {@link android.graphics.Color#GRAY}. |
| 5307 | * |
| 5308 | * <p>The confirm credentials screen can be created using |
| 5309 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5310 | * |
| 5311 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5312 | * @param color The 32bit representation of the color to be used. |
| 5313 | */ |
| 5314 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5315 | try { |
| 5316 | mService.setOrganizationColor(admin, color); |
| 5317 | } catch (RemoteException re) { |
| 5318 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5319 | } |
| 5320 | } |
| 5321 | |
| 5322 | /** |
| 5323 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5324 | * This color is used as background color of the confirm credentials screen for that user. |
| 5325 | * |
| 5326 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5327 | * @return The 32bit representation of the color to be used. |
| 5328 | */ |
| 5329 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 5330 | try { |
| 5331 | return mService.getOrganizationColor(admin); |
| 5332 | } catch (RemoteException re) { |
| 5333 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5334 | return 0; |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | /** |
| 5339 | * @hide |
| 5340 | * Retrieve the customization color for a given user. |
| 5341 | * |
| 5342 | * @param userHandle The user id of the user we're interested in. |
| 5343 | * @return The 32bit representation of the color to be used. |
| 5344 | */ |
| 5345 | public int getOrganizationColorForUser(int userHandle) { |
| 5346 | try { |
| 5347 | return mService.getOrganizationColorForUser(userHandle); |
| 5348 | } catch (RemoteException re) { |
| 5349 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5350 | return 0; |
| 5351 | } |
| 5352 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5353 | |
| 5354 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5355 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 5356 | * return {@link #STATE_USER_UNMANAGED} |
| 5357 | * @hide |
| 5358 | */ |
| 5359 | @UserProvisioningState |
| 5360 | public int getUserProvisioningState() { |
| 5361 | if (mService != null) { |
| 5362 | try { |
| 5363 | return mService.getUserProvisioningState(); |
| 5364 | } catch (RemoteException e) { |
| 5365 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5366 | } |
| 5367 | } |
| 5368 | return STATE_USER_UNMANAGED; |
| 5369 | } |
| 5370 | |
| 5371 | /** |
| 5372 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 5373 | * |
| 5374 | * @param state to store |
| 5375 | * @param userHandle for user |
| 5376 | * @hide |
| 5377 | */ |
| 5378 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 5379 | if (mService != null) { |
| 5380 | try { |
| 5381 | mService.setUserProvisioningState(state, userHandle); |
| 5382 | } catch (RemoteException e) { |
| 5383 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5384 | } |
| 5385 | } |
| 5386 | } |
| 5387 | |
| 5388 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5389 | * @hide |
| 5390 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 5391 | * affiliated if it is managed by the same entity as the device. |
| 5392 | * |
| 5393 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 5394 | * user/profile is considered affiliated if the following conditions are both met: |
| 5395 | * <ul> |
| 5396 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 5397 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 5398 | * and a profile owner intersect, they must have come from the same source, which means that |
| 5399 | * the device owner and profile owner are controlled by the same entity.</li> |
| 5400 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 5401 | * </ul> |
| 5402 | * |
| 5403 | * @param admin Which profile or device owner this request is associated with. |
| 5404 | * @param ids A set of opaque affiliation ids. |
| 5405 | */ |
| 5406 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 5407 | try { |
| 5408 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 5409 | } catch (RemoteException e) { |
| 5410 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5411 | } |
| 5412 | } |
| 5413 | |
| 5414 | /** |
| 5415 | * @hide |
| 5416 | * Returns whether this user/profile is affiliated with the device. See |
| 5417 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 5418 | * |
| 5419 | * @return whether this user/profile is affiliated with the device. |
| 5420 | */ |
| 5421 | public boolean isAffiliatedUser() { |
| 5422 | try { |
| 5423 | return mService != null && mService.isAffiliatedUser(); |
| 5424 | } catch (RemoteException e) { |
| 5425 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5426 | return false; |
| 5427 | } |
| 5428 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5429 | } |