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; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 26 | import android.auditing.SecurityLog; |
| 27 | import android.auditing.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 30 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 31 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
| 33 | import android.content.pm.PackageManager; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 34 | import android.content.pm.ParceledListSlice; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 35 | import android.content.pm.ResolveInfo; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 36 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 38 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 39 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 40 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 41 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 42 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 43 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 44 | import android.os.RemoteException; |
| 45 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 46 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 47 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 48 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 49 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 50 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 51 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 52 | import android.util.Log; |
| 53 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 54 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 55 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 56 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 57 | import org.xmlpull.v1.XmlPullParserException; |
| 58 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 59 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 60 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 61 | import java.lang.annotation.Retention; |
| 62 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 63 | import java.net.InetSocketAddress; |
| 64 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 65 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 66 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 67 | import java.security.PrivateKey; |
| 68 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 69 | import java.security.cert.CertificateException; |
| 70 | import java.security.cert.CertificateFactory; |
| 71 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 72 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 73 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 74 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 75 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 76 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 77 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 80 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 81 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 82 | * <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] | 83 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 84 | * accessible to all device administrators unless the documentation for that method specifies that |
| 85 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 86 | * |
| 87 | * <div class="special reference"> |
| 88 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 89 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 90 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 91 | * developer guide. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 92 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 93 | */ |
| 94 | public class DevicePolicyManager { |
| 95 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 96 | |
| 97 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 99 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 100 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 101 | private static final String REMOTE_EXCEPTION_MESSAGE = |
| 102 | "Failed to talk with device policy manager service"; |
| 103 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 104 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 105 | this(context, |
| 106 | IDevicePolicyManager.Stub.asInterface( |
| 107 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 108 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 111 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 112 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 113 | protected DevicePolicyManager( |
| 114 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 115 | mContext = context; |
| 116 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 117 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** @hide */ |
| 121 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 122 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 123 | return me.mService != null ? me : null; |
| 124 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 125 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 126 | /** @hide test will override it. */ |
| 127 | @VisibleForTesting |
| 128 | protected int myUserId() { |
| 129 | return UserHandle.myUserId(); |
| 130 | } |
| 131 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 132 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 133 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 134 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 135 | * <p>A managed profile allows data separation for example for the usage of a |
| 136 | * device as a personal and corporate device. The user which provisioning is started from and |
| 137 | * the managed profile share a launcher. |
| 138 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 139 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 140 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 141 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 142 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 143 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 144 | * {@link #isProvisioningAllowed(String)}. |
| 145 | * |
| 146 | * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 147 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 148 | * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 149 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 150 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 151 | * |
| 152 | * <p> The intent may also contain the following extras: |
| 153 | * <ul> |
| 154 | * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li> |
| 155 | * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li> |
| 156 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 157 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 158 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 159 | * in the provisioning intent. The |
| 160 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 161 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 162 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 163 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 164 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 165 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 166 | * |
| 167 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 168 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 169 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 170 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 171 | * 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] | 172 | */ |
| 173 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 174 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 175 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 176 | |
| 177 | /** |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 178 | * @hide |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 179 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 180 | * |
| 181 | * <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] | 182 | * 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] | 183 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 184 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 185 | * allowed. |
| 186 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 187 | * <p>This intent should contain the extra |
| 188 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 189 | * |
| 190 | * <p> If provisioning fails, the device returns to its previous state. |
| 191 | * |
| 192 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 193 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 194 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 195 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 196 | * 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] | 197 | */ |
| 198 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 199 | public static final String ACTION_PROVISION_MANAGED_USER |
| 200 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 201 | |
| 202 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 203 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 204 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 205 | * |
| 206 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 207 | * A device owner has full control over the device. The device owner can not be modified by the |
| 208 | * user. |
| 209 | * |
| 210 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 211 | * employee or client. |
| 212 | * |
| 213 | * <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] | 214 | * It is possible to check if provisioning is allowed or not by querying the method |
| 215 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 216 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 217 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 218 | * <ul> |
| 219 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 220 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 221 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 222 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 223 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 224 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 225 | * </ul> |
| 226 | * |
| 227 | * <p> When device owner provisioning has completed, an intent of the type |
| 228 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 229 | * device owner. |
| 230 | * |
| 231 | * <p> If provisioning fails, the device is factory reset. |
| 232 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 233 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 234 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 235 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 236 | * 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] | 237 | */ |
| 238 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 239 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 240 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 241 | |
| 242 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 243 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 244 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 245 | * |
| 246 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 247 | * management state that is distinct from that reached by |
| 248 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 249 | * user, and only has control over device-wide policies, not individual users and their data. |
| 250 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 251 | * this form of device management. |
| 252 | * |
| 253 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 254 | * A device owner has full control over the device. The device owner can not be modified by the |
| 255 | * user. |
| 256 | * |
| 257 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 258 | * employee or client. |
| 259 | * |
| 260 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 261 | * It is possible to check if provisioning is allowed or not by querying the method |
| 262 | * {@link #isProvisioningAllowed(String)}. |
| 263 | * |
| 264 | * <p>The intent contains the following extras: |
| 265 | * <ul> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 270 | * </ul> |
| 271 | * |
| 272 | * <p> When device owner provisioning has completed, an intent of the type |
| 273 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 274 | * device owner. |
| 275 | * |
| 276 | * <p> If provisioning fails, the device is factory reset. |
| 277 | * |
| 278 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 279 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 280 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 281 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 282 | * |
| 283 | * @hide |
| 284 | */ |
| 285 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 286 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 287 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 288 | |
| 289 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 290 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 291 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 292 | * <ul> |
| 293 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 294 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 295 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 296 | * </ul> |
| 297 | * |
| 298 | * @hide |
| 299 | */ |
| 300 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 301 | public static final String ACTION_PROVISION_FINALIZATION |
| 302 | = "android.app.action.PROVISION_FINALIZATION"; |
| 303 | |
| 304 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 305 | * 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] | 306 | * allows a mobile device management application or NFC programmer application which starts |
| 307 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 308 | * <p> |
| 309 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 310 | * sends the intent to pass data to itself on the newly created profile. |
| 311 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 312 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 313 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 314 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 315 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 316 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 317 | * management application after provisioning. |
| 318 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 319 | * <p> |
| 320 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 321 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 322 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 323 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 324 | */ |
| 325 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 326 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 327 | |
| 328 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 329 | * A String extra holding the package name of the mobile device management application that |
| 330 | * will be set as the profile owner or device owner. |
| 331 | * |
| 332 | * <p>If an application starts provisioning directly via an intent with action |
| 333 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 334 | * application that started provisioning. The package will be set as profile owner in that case. |
| 335 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 336 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 337 | * 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] | 338 | * |
| 339 | * <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] | 340 | * 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] | 341 | |
| 342 | * @see DeviceAdminReceiver |
| 343 | * @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] | 344 | * supported, but only if there is only one device admin receiver in the package that requires |
| 345 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 346 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 347 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 348 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 349 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 350 | |
| 351 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 352 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 353 | * application that will be set as the profile owner or device owner and active admin. |
| 354 | * |
| 355 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 356 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 357 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 358 | * 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] | 359 | * |
| 360 | * <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] | 361 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 362 | * message containing an NFC record with MIME type |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 363 | * {@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] | 364 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 365 | * |
| 366 | * @see DeviceAdminReceiver |
| 367 | */ |
| 368 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 369 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 370 | |
| 371 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 372 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 373 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 374 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 375 | * |
| 376 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 377 | */ |
| 378 | |
| 379 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 380 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 381 | |
| 382 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 383 | * A String extra that, holds the email address of the account which a managed profile is |
| 384 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 385 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 386 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 387 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 388 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 389 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 390 | * contains this extra, it is forwarded in the |
| 391 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 392 | * device management application that was set as the profile owner during provisioning. |
| 393 | * 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] | 394 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 395 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 396 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 397 | |
| 398 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 399 | * A integer extra indicating the predominant color to show during the provisioning. |
| 400 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 401 | * |
| 402 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 403 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 404 | */ |
| 405 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 406 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 407 | |
| 408 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 409 | * 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] | 410 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 411 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 412 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 413 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 414 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 415 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 416 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 417 | |
| 418 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 419 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 420 | * will be set to. |
| 421 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 422 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 423 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 424 | */ |
| 425 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 426 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 427 | |
| 428 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 429 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 430 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 431 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 432 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 433 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 434 | */ |
| 435 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 436 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 437 | |
| 438 | /** |
| 439 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 440 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 441 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 442 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 443 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 444 | */ |
| 445 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 446 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 447 | |
| 448 | /** |
| 449 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 450 | * owner provisioning for downloading the mobile device management application. |
| 451 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 452 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 453 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 454 | */ |
| 455 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 456 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 457 | |
| 458 | /** |
| 459 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 460 | * is hidden or not. |
| 461 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 462 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 463 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 464 | */ |
| 465 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 466 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 467 | |
| 468 | /** |
| 469 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 470 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 471 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 472 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 473 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 474 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 475 | */ |
| 476 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 477 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 478 | |
| 479 | /** |
| 480 | * A String extra holding the password of the wifi network in |
| 481 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 482 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 483 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 484 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 485 | */ |
| 486 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 487 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 488 | |
| 489 | /** |
| 490 | * A String extra holding the proxy host for the wifi network in |
| 491 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 492 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 493 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 494 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 495 | */ |
| 496 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 497 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 498 | |
| 499 | /** |
| 500 | * An int extra holding the proxy port for the wifi network in |
| 501 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 502 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 503 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 504 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 505 | */ |
| 506 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 507 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 508 | |
| 509 | /** |
| 510 | * A String extra holding the proxy bypass for the wifi network in |
| 511 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 512 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 513 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 514 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 515 | */ |
| 516 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 517 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 518 | |
| 519 | /** |
| 520 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 521 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 522 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 523 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 524 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 525 | */ |
| 526 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 527 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 528 | |
| 529 | /** |
| 530 | * A String extra holding a url that specifies the download location of the device admin |
| 531 | * package. When not provided it is assumed that the device admin package is already installed. |
| 532 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 533 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 534 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 535 | */ |
| 536 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 537 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 538 | |
| 539 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 540 | * An int extra holding a minimum required version code for the device admin package. If the |
| 541 | * device admin is already installed on the device, it will only be re-downloaded from |
| 542 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 543 | * installed package is less than this version code. |
| 544 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 545 | * <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] | 546 | * provisioning via an NFC bump. |
| 547 | */ |
| 548 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 549 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 550 | |
| 551 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 552 | * A String extra holding a http cookie header which should be used in the http request to the |
| 553 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 554 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 555 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 556 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 557 | */ |
| 558 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 559 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 560 | |
| 561 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 562 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 563 | * the file at download location specified in |
| 564 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 565 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 566 | * <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] | 567 | * present. The provided checksum should match the checksum of the file at the download |
| 568 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 569 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 570 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 571 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 572 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 573 | * |
| 574 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 575 | * 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] | 576 | * 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] | 577 | * 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] | 578 | */ |
| 579 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 580 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 581 | |
| 582 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 583 | * 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] | 584 | * android package archive at the download location specified in {@link |
| 585 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 586 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 587 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 588 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 589 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 590 | * |
| 591 | * <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] | 592 | * 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] | 593 | * the download location. If the checksum does not match an error will be shown to the user and |
| 594 | * the user will be asked to factory reset the device. |
| 595 | * |
| 596 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 597 | * provisioning via an NFC bump. |
| 598 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 599 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 600 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 601 | |
| 602 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 603 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 604 | * has completed successfully. |
| 605 | * |
| 606 | * <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] | 607 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 608 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 609 | * <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] | 610 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 611 | */ |
| 612 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 613 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 614 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 615 | |
| 616 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 617 | * 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] | 618 | * provisioning. |
| 619 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 620 | * <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] | 621 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 622 | */ |
| 623 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 624 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 625 | |
| 626 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 627 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 628 | * provisioning. If this extra is not passed, a default image will be shown. |
| 629 | * <h5>The following URI schemes are accepted:</h5> |
| 630 | * <ul> |
| 631 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 632 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 633 | * </ul> |
| 634 | * |
| 635 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 636 | * pixed density for the device. |
| 637 | * |
| 638 | * <p> If a content: URI is passed, the intent should have the flag |
| 639 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 640 | * {@link android.content.ClipData} of the intent too. |
| 641 | * |
| 642 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 643 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 644 | */ |
| 645 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 646 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 647 | |
| 648 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 649 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 650 | * during setup-wizard. |
| 651 | * |
| 652 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 653 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 654 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 655 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 656 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 657 | * |
| 658 | * @hide |
| 659 | */ |
| 660 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 661 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 662 | |
| 663 | /** |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 664 | * This MIME type is used for starting the Device Owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 665 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 666 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 667 | * A device owner has full control over the device. The device owner can not be modified by the |
| 668 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 669 | * reset. |
| 670 | * |
| 671 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 672 | * employee or client. |
| 673 | * |
| 674 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 675 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 676 | * <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] | 677 | * contains the following properties: |
| 678 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 679 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 680 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 681 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 682 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 683 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 684 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 685 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 686 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 687 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 688 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 689 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 690 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 691 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 692 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 693 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 694 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 695 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 696 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 697 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 698 | * 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] | 699 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 700 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 701 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 702 | */ |
| 703 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 704 | = "application/com.android.managedprovisioning"; |
| 705 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 706 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 707 | * Activity action: ask the user to add a new device administrator to the system. |
| 708 | * The desired policy is the ComponentName of the policy in the |
| 709 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 710 | * bring the user through adding the device administrator to the system (or |
| 711 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 712 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 713 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 714 | * field to provide the user with additional explanation (in addition |
| 715 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 716 | * |
| 717 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 718 | * user intervention). However, if your administrator has been updated and is requesting |
| 719 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 720 | * 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] | 721 | */ |
| 722 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 723 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 724 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 725 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 726 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 727 | * @hide |
| 728 | * 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] | 729 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 730 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 731 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 732 | * 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] | 733 | * to remotely control restrictions on the user. |
| 734 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 735 | * <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] | 736 | * result of whether or not the user approved the action. If approved, the result will |
| 737 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 738 | * as a profile owner. |
| 739 | * |
| 740 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 741 | * field to provide the user with additional explanation (in addition |
| 742 | * to your component's description) about what is being added. |
| 743 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 744 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 745 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 746 | */ |
| 747 | @SystemApi |
| 748 | public static final String ACTION_SET_PROFILE_OWNER |
| 749 | = "android.app.action.SET_PROFILE_OWNER"; |
| 750 | |
| 751 | /** |
| 752 | * @hide |
| 753 | * Name of the profile owner admin that controls the user. |
| 754 | */ |
| 755 | @SystemApi |
| 756 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 757 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 758 | |
| 759 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 760 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 761 | * 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] | 762 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 763 | * @hide |
| 764 | */ |
| 765 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 766 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 767 | |
| 768 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 769 | * Broadcast action: sent when the device owner is set or changed. |
| 770 | * |
| 771 | * This broadcast is sent only to the primary user. |
| 772 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 773 | */ |
| 774 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 775 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 776 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 777 | |
| 778 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 779 | * The ComponentName of the administrator component. |
| 780 | * |
| 781 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 782 | */ |
| 783 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 784 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 785 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 786 | * An optional CharSequence providing additional explanation for why the |
| 787 | * admin is being added. |
| 788 | * |
| 789 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 790 | */ |
| 791 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 792 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 793 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 794 | * Activity action: have the user enter a new password. This activity should |
| 795 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 796 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 797 | * enter a new password that meets the current requirements. You can use |
| 798 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 799 | * have the user select a new password in order to meet the current |
| 800 | * constraints. Upon being resumed from this activity, you can check the new |
| 801 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 802 | * |
| 803 | * If the intent is launched from within a managed profile with a profile |
| 804 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 805 | * this will trigger entering a new password for the parent of the profile. |
| 806 | * For all other cases it will trigger entering a new password for the user |
| 807 | * or profile it is launched from. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 808 | */ |
| 809 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 810 | public static final String ACTION_SET_NEW_PASSWORD |
| 811 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 812 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 813 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 814 | * Activity action: have the user enter a new password for the parent profile. |
| 815 | * If the intent is launched from within a managed profile, this will trigger |
| 816 | * entering a new password for the parent of the profile. In all other cases |
| 817 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 818 | */ |
| 819 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 820 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 821 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 822 | |
| 823 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 824 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 825 | * the parent profile to access intents sent from the managed profile. |
| 826 | * That is, when an app in the managed profile calls |
| 827 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 828 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 829 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 830 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 831 | |
| 832 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 833 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 834 | * the managed profile to access intents sent from the parent profile. |
| 835 | * That is, when an app in the parent profile calls |
| 836 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 837 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 838 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 839 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 840 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 841 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 842 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 843 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 844 | */ |
| 845 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 846 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 847 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 848 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 849 | /** |
| 850 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 851 | * Already granted or denied permissions are not affected by this. |
| 852 | */ |
| 853 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 854 | |
| 855 | /** |
| 856 | * Permission policy to always grant new permission requests for runtime permissions. |
| 857 | * Already granted or denied permissions are not affected by this. |
| 858 | */ |
| 859 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 860 | |
| 861 | /** |
| 862 | * Permission policy to always deny new permission requests for runtime permissions. |
| 863 | * Already granted or denied permissions are not affected by this. |
| 864 | */ |
| 865 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 866 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 867 | /** |
| 868 | * Runtime permission state: The user can manage the permission |
| 869 | * through the UI. |
| 870 | */ |
| 871 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 872 | |
| 873 | /** |
| 874 | * Runtime permission state: The permission is granted to the app |
| 875 | * and the user cannot manage the permission through the UI. |
| 876 | */ |
| 877 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 878 | |
| 879 | /** |
| 880 | * Runtime permission state: The permission is denied to the app |
| 881 | * and the user cannot manage the permission through the UI. |
| 882 | */ |
| 883 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 884 | |
| 885 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 886 | * No management for current user in-effect. This is the default. |
| 887 | * @hide |
| 888 | */ |
| 889 | public static final int STATE_USER_UNMANAGED = 0; |
| 890 | |
| 891 | /** |
| 892 | * Management partially setup, user setup needs to be completed. |
| 893 | * @hide |
| 894 | */ |
| 895 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 896 | |
| 897 | /** |
| 898 | * Management partially setup, user setup completed. |
| 899 | * @hide |
| 900 | */ |
| 901 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 902 | |
| 903 | /** |
| 904 | * Management setup and active on current user. |
| 905 | * @hide |
| 906 | */ |
| 907 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 908 | |
| 909 | /** |
| 910 | * Management partially setup on a managed profile. |
| 911 | * @hide |
| 912 | */ |
| 913 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 914 | |
| 915 | /** |
| 916 | * @hide |
| 917 | */ |
| 918 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 919 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 920 | @Retention(RetentionPolicy.SOURCE) |
| 921 | public @interface UserProvisioningState {} |
| 922 | |
| 923 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 924 | * Return true if the given administrator component is currently |
| 925 | * active (enabled) in the system. |
| 926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 927 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 928 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /** |
| 932 | * @see #isAdminActive(ComponentName) |
| 933 | * @hide |
| 934 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 935 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 936 | if (mService != null) { |
| 937 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 938 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 939 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 940 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | return false; |
| 944 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 945 | /** |
| 946 | * Return true if the given administrator component is currently being removed |
| 947 | * for the user. |
| 948 | * @hide |
| 949 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 950 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 951 | if (mService != null) { |
| 952 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 953 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 954 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 955 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | return false; |
| 959 | } |
| 960 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 961 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 962 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 963 | * Return a list of all currently active device administrators' component |
| 964 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 965 | * returned. |
| 966 | */ |
| 967 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 968 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | /** |
| 972 | * @see #getActiveAdmins() |
| 973 | * @hide |
| 974 | */ |
| 975 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 976 | if (mService != null) { |
| 977 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 978 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 979 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 980 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | return null; |
| 984 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 985 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 986 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 987 | * Used by package administration code to determine if a package can be stopped |
| 988 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 989 | * @hide |
| 990 | */ |
| 991 | public boolean packageHasActiveAdmins(String packageName) { |
| 992 | if (mService != null) { |
| 993 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 994 | return mService.packageHasActiveAdmins(packageName, myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 995 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 996 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | return false; |
| 1000 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1001 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1002 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1003 | * Remove a current administration component. This can only be called |
| 1004 | * by the application that owns the administration component; if you |
| 1005 | * try to remove someone else's component, a security exception will be |
| 1006 | * thrown. |
| 1007 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1008 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1009 | if (mService != null) { |
| 1010 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1011 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1012 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1013 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1017 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1018 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1019 | * 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] | 1020 | * 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] | 1021 | * but requires additional policies after an upgrade. |
| 1022 | * |
| 1023 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 1024 | * an active administrator, or an exception will be thrown. |
| 1025 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 1026 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1027 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1028 | if (mService != null) { |
| 1029 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1030 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1031 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1032 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | return false; |
| 1036 | } |
| 1037 | |
| 1038 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1039 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1040 | * |
| 1041 | * @hide |
| 1042 | */ |
| 1043 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1044 | if (mService != null) { |
| 1045 | try { |
| 1046 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1047 | } catch (RemoteException e) { |
| 1048 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1049 | } |
| 1050 | } |
| 1051 | return false; |
| 1052 | } |
| 1053 | |
| 1054 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1055 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1056 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1057 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1058 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1059 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1060 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1061 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1062 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1063 | * recognition technology. This implies technologies that can recognize the identity of |
| 1064 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1065 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1066 | */ |
| 1067 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1068 | |
| 1069 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1070 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1071 | * 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] | 1072 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1073 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1074 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1075 | |
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 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1078 | * password containing at least numeric characters. Note that quality |
| 1079 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1080 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1081 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1082 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1083 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1084 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1085 | * password containing at least numeric characters with no repeating (4444) |
| 1086 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1087 | * constants are ordered so that higher values are more restrictive. |
| 1088 | */ |
| 1089 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1090 | |
| 1091 | /** |
| 1092 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1093 | * password containing at least alphabetic (or other symbol) characters. |
| 1094 | * Note that quality constants are ordered so that higher values are more |
| 1095 | * restrictive. |
| 1096 | */ |
| 1097 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1098 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1099 | /** |
| 1100 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1101 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1102 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1103 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1104 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1105 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1106 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1107 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1108 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1109 | * password containing at least a letter, a numerical digit and a special |
| 1110 | * symbol, by default. With this password quality, passwords can be |
| 1111 | * restricted to contain various sets of characters, like at least an |
| 1112 | * uppercase letter, etc. These are specified using various methods, |
| 1113 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1114 | * that quality constants are ordered so that higher values are more |
| 1115 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1116 | */ |
| 1117 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1118 | |
| 1119 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1120 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1121 | * modify password. In case this password quality is set, the password is |
| 1122 | * managed by a profile owner. The profile owner can set any password, |
| 1123 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1124 | * that quality constants are ordered so that higher values are more |
| 1125 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1126 | * the highest. |
| 1127 | * @hide |
| 1128 | */ |
| 1129 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1130 | |
| 1131 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1132 | * Called by an application that is administering the device to set the |
| 1133 | * password restrictions it is imposing. After setting this, the user |
| 1134 | * will not be able to enter a new password that is not at least as |
| 1135 | * restrictive as what has been set. Note that the current password |
| 1136 | * will remain until the user has set a new one, so the change does not |
| 1137 | * take place immediately. To prompt the user for a new password, use |
| 1138 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1139 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1140 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 1141 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1142 | * the user's preference, and any other considerations) is the one that |
| 1143 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1144 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1145 | * <p>The calling device admin must have requested |
| 1146 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1147 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1148 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1149 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1150 | * @param quality The new desired quality. One of |
| 1151 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1152 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1153 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1154 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1155 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1156 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1157 | if (mService != null) { |
| 1158 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1159 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1160 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1161 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1165 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1166 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1167 | * Retrieve the current minimum password quality for all admins of this user |
| 1168 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1169 | * @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] | 1170 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1171 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1172 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1173 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1177 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1178 | if (mService != null) { |
| 1179 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1180 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1181 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1182 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1183 | } |
| 1184 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1185 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1186 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1187 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1188 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1189 | * Called by an application that is administering the device to set the |
| 1190 | * minimum allowed password length. After setting this, the user |
| 1191 | * will not be able to enter a new password that is not at least as |
| 1192 | * restrictive as what has been set. Note that the current password |
| 1193 | * will remain until the user has set a new one, so the change does not |
| 1194 | * take place immediately. To prompt the user for a new password, use |
| 1195 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1196 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1197 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1198 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1199 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1200 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1201 | * <p>The calling device admin must have requested |
| 1202 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1203 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1204 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1205 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1206 | * @param length The new desired minimum password length. A value of 0 |
| 1207 | * means there is no restriction. |
| 1208 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1209 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1210 | if (mService != null) { |
| 1211 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1212 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1213 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1214 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1218 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1219 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1220 | * Retrieve the current minimum password length for all admins of this |
| 1221 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1222 | * @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] | 1223 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1224 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1225 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1226 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1230 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1231 | if (mService != null) { |
| 1232 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1233 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1234 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1235 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | return 0; |
| 1239 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1240 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1241 | /** |
| 1242 | * Called by an application that is administering the device to set the |
| 1243 | * minimum number of upper case letters required in the password. After |
| 1244 | * setting this, the user will not be able to enter a new password that is |
| 1245 | * not at least as restrictive as what has been set. Note that the current |
| 1246 | * password will remain until the user has set a new one, so the change does |
| 1247 | * not take place immediately. To prompt the user for a new password, use |
| 1248 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1249 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1250 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1251 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1252 | * <p> |
| 1253 | * The calling device admin must have requested |
| 1254 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1255 | * this method; if it has not, a security exception will be thrown. |
| 1256 | * |
| 1257 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1258 | * with. |
| 1259 | * @param length The new desired minimum number of upper case letters |
| 1260 | * required in the password. A value of 0 means there is no |
| 1261 | * restriction. |
| 1262 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1263 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1264 | if (mService != null) { |
| 1265 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1266 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1267 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1268 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1275 | * password for all admins of this user and its profiles or a particular one. |
| 1276 | * This is the same value as set by |
| 1277 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1278 | * and only applies when the password quality is |
| 1279 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1280 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1281 | * @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] | 1282 | * aggregate all admins. |
| 1283 | * @return The minimum number of upper case letters required in the |
| 1284 | * password. |
| 1285 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1286 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1287 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1291 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1292 | if (mService != null) { |
| 1293 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1294 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1295 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1296 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1297 | } |
| 1298 | } |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | /** |
| 1303 | * Called by an application that is administering the device to set the |
| 1304 | * minimum number of lower case letters required in the password. After |
| 1305 | * setting this, the user will not be able to enter a new password that is |
| 1306 | * not at least as restrictive as what has been set. Note that the current |
| 1307 | * password will remain until the user has set a new one, so the change does |
| 1308 | * not take place immediately. To prompt the user for a new password, use |
| 1309 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1310 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1311 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1312 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1313 | * <p> |
| 1314 | * The calling device admin must have requested |
| 1315 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1316 | * this method; if it has not, a security exception will be thrown. |
| 1317 | * |
| 1318 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1319 | * with. |
| 1320 | * @param length The new desired minimum number of lower case letters |
| 1321 | * required in the password. A value of 0 means there is no |
| 1322 | * restriction. |
| 1323 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1324 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1325 | if (mService != null) { |
| 1326 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1327 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1328 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1329 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | /** |
| 1335 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1336 | * password for all admins of this user and its profiles or a particular one. |
| 1337 | * This is the same value as set by |
| 1338 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1339 | * and only applies when the password quality is |
| 1340 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1341 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1342 | * @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] | 1343 | * aggregate all admins. |
| 1344 | * @return The minimum number of lower case letters required in the |
| 1345 | * password. |
| 1346 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1347 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1348 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1352 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1353 | if (mService != null) { |
| 1354 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1355 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1356 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1357 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1358 | } |
| 1359 | } |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * Called by an application that is administering the device to set the |
| 1365 | * minimum number of letters required in the password. After setting this, |
| 1366 | * the user will not be able to enter a new password that is not at least as |
| 1367 | * restrictive as what has been set. Note that the current password will |
| 1368 | * remain until the user has set a new one, so the change does not take |
| 1369 | * place immediately. To prompt the user for a new password, use |
| 1370 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1371 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1372 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1373 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1374 | * <p> |
| 1375 | * The calling device admin must have requested |
| 1376 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1377 | * this method; if it has not, a security exception will be thrown. |
| 1378 | * |
| 1379 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1380 | * with. |
| 1381 | * @param length The new desired minimum number of letters required in the |
| 1382 | * password. A value of 0 means there is no restriction. |
| 1383 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1384 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1385 | if (mService != null) { |
| 1386 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1387 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1388 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1389 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | /** |
| 1395 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1396 | * admins or a particular one. This is the same value as |
| 1397 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 1398 | * and only applies when the password quality is |
| 1399 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1400 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1401 | * @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] | 1402 | * aggregate all admins. |
| 1403 | * @return The minimum number of letters required in the password. |
| 1404 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1405 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1406 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1410 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1411 | if (mService != null) { |
| 1412 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1413 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1414 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1415 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | /** |
| 1422 | * Called by an application that is administering the device to set the |
| 1423 | * minimum number of numerical digits required in the password. After |
| 1424 | * setting this, the user will not be able to enter a new password that is |
| 1425 | * not at least as restrictive as what has been set. Note that the current |
| 1426 | * password will remain until the user has set a new one, so the change does |
| 1427 | * not take place immediately. To prompt the user for a new password, use |
| 1428 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1429 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1430 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1431 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1432 | * <p> |
| 1433 | * The calling device admin must have requested |
| 1434 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1435 | * this method; if it has not, a security exception will be thrown. |
| 1436 | * |
| 1437 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1438 | * with. |
| 1439 | * @param length The new desired minimum number of numerical digits required |
| 1440 | * in the password. A value of 0 means there is no restriction. |
| 1441 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1442 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1443 | if (mService != null) { |
| 1444 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1445 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1446 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1447 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1454 | * for all admins of this user and its profiles or a particular one. |
| 1455 | * This is the same value as set by |
| 1456 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1457 | * and only applies when the password quality is |
| 1458 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1459 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1460 | * @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] | 1461 | * aggregate all admins. |
| 1462 | * @return The minimum number of numerical digits required in the password. |
| 1463 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1464 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1465 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1469 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1470 | if (mService != null) { |
| 1471 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1472 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1473 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1474 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | return 0; |
| 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * Called by an application that is administering the device to set the |
| 1482 | * minimum number of symbols required in the password. After setting this, |
| 1483 | * the user will not be able to enter a new password that is not at least as |
| 1484 | * restrictive as what has been set. Note that the current password will |
| 1485 | * remain until the user has set a new one, so the change does not take |
| 1486 | * place immediately. To prompt the user for a new password, use |
| 1487 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1488 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1489 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1490 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1491 | * <p> |
| 1492 | * The calling device admin must have requested |
| 1493 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1494 | * this method; if it has not, a security exception will be thrown. |
| 1495 | * |
| 1496 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1497 | * with. |
| 1498 | * @param length The new desired minimum number of symbols required in the |
| 1499 | * password. A value of 0 means there is no restriction. |
| 1500 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1501 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1502 | if (mService != null) { |
| 1503 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1504 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1505 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1506 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1513 | * admins or a particular one. This is the same value as |
| 1514 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1515 | * and only applies when the password quality is |
| 1516 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1517 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1518 | * @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] | 1519 | * aggregate all admins. |
| 1520 | * @return The minimum number of symbols required in the password. |
| 1521 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1522 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1523 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1527 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1528 | if (mService != null) { |
| 1529 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1530 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1531 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1532 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1538 | /** |
| 1539 | * Called by an application that is administering the device to set the |
| 1540 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1541 | * required in the password. After setting this, the user will not be able |
| 1542 | * to enter a new password that is not at least as restrictive as what has |
| 1543 | * been set. Note that the current password will remain until the user has |
| 1544 | * set a new one, so the change does not take place immediately. To prompt |
| 1545 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1546 | * setting this value. This constraint is only imposed if the administrator |
| 1547 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1548 | * {@link #setPasswordQuality}. The default value is 0. |
| 1549 | * <p> |
| 1550 | * The calling device admin must have requested |
| 1551 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1552 | * this method; if it has not, a security exception will be thrown. |
| 1553 | * |
| 1554 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1555 | * with. |
| 1556 | * @param length The new desired minimum number of letters required in the |
| 1557 | * password. A value of 0 means there is no restriction. |
| 1558 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1559 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1560 | if (mService != null) { |
| 1561 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1562 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1563 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1564 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | /** |
| 1570 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1571 | * password for all admins of this user and its profiles or a particular one. |
| 1572 | * This is the same value as set by |
| 1573 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1574 | * and only applies when the password quality is |
| 1575 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1576 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1577 | * @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] | 1578 | * aggregate all admins. |
| 1579 | * @return The minimum number of letters required in the password. |
| 1580 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1581 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1582 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1586 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1587 | if (mService != null) { |
| 1588 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1589 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1590 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1591 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1597 | /** |
| 1598 | * Called by an application that is administering the device to set the length |
| 1599 | * of the password history. After setting this, the user will not be able to |
| 1600 | * enter a new password that is the same as any password in the history. Note |
| 1601 | * that the current password will remain until the user has set a new one, so |
| 1602 | * the change does not take place immediately. To prompt the user for a new |
| 1603 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1604 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1605 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1606 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1607 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1608 | * |
| 1609 | * <p> |
| 1610 | * The calling device admin must have requested |
| 1611 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1612 | * method; if it has not, a security exception will be thrown. |
| 1613 | * |
| 1614 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1615 | * with. |
| 1616 | * @param length The new desired length of password history. A value of 0 |
| 1617 | * means there is no restriction. |
| 1618 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1619 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1620 | if (mService != null) { |
| 1621 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1622 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1623 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1624 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1630 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1631 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1632 | * the device password (for all admins). |
| 1633 | * |
| 1634 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1635 | * For example, to have the password expire 5 days from now, timeout would be |
| 1636 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1637 | * |
| 1638 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1639 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1640 | * <p>The calling device admin must have requested |
| 1641 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1642 | * method; if it has not, a security exception will be thrown. |
| 1643 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1644 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1645 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1646 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1647 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1648 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1649 | * means there is no restriction (unlimited). |
| 1650 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1651 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1652 | if (mService != null) { |
| 1653 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1654 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1655 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1656 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1657 | } |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1662 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1663 | * recurring expiration timeout provided in the call to |
| 1664 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1665 | * aggregate of all policy administrators if {@code admin} is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1666 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1667 | * @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] | 1668 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1669 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1670 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1671 | if (mService != null) { |
| 1672 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1673 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1674 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1675 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | return 0; |
| 1679 | } |
| 1680 | |
| 1681 | /** |
| 1682 | * 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] | 1683 | * all admins of this user and its profiles if admin is null. If the password is |
| 1684 | * expired, this will return the time since the password expired as a negative number. |
| 1685 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1686 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1687 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1688 | * @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] | 1689 | * @return The password expiration time, in ms. |
| 1690 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1691 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1692 | if (mService != null) { |
| 1693 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1694 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1695 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1696 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | return 0; |
| 1700 | } |
| 1701 | |
| 1702 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1703 | * Retrieve the current password history length for all admins of this |
| 1704 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1705 | * @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] | 1706 | * all admins. |
| 1707 | * @return The length of the password history |
| 1708 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1709 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1710 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1714 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1715 | if (mService != null) { |
| 1716 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1717 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1718 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1719 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | return 0; |
| 1723 | } |
| 1724 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1725 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1726 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1727 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1728 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1729 | * @return Returns the maximum length that the user can enter. |
| 1730 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1731 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1732 | // Kind-of arbitrary. |
| 1733 | return 16; |
| 1734 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1735 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1736 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1737 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1738 | * to meet the policy requirements (quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1739 | * 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] | 1740 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1741 | * <p>The calling device admin must have requested |
| 1742 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1743 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1744 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1745 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1746 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1747 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1748 | if (mService != null) { |
| 1749 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1750 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1751 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1752 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1753 | } |
| 1754 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1755 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1756 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1757 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1758 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1759 | * Determine whether the current profile password the user has set is sufficient |
| 1760 | * to meet the policy requirements (quality, minimum length) that have been |
| 1761 | * requested by the admins of the parent user and its profiles. |
| 1762 | * |
| 1763 | * @param userHandle the userId of the profile to check the password for. |
| 1764 | * @return Returns true if the password would meet the current requirements, else false. |
| 1765 | * @hide |
| 1766 | */ |
| 1767 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 1768 | if (mService != null) { |
| 1769 | try { |
| 1770 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 1771 | } catch (RemoteException e) { |
| 1772 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1773 | } |
| 1774 | } |
| 1775 | return false; |
| 1776 | } |
| 1777 | |
| 1778 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1779 | * Retrieve the number of times the user has failed at entering a |
| 1780 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1781 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1782 | * <p>The calling device admin must have requested |
| 1783 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1784 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1785 | */ |
| 1786 | public int getCurrentFailedPasswordAttempts() { |
| 1787 | if (mService != null) { |
| 1788 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1789 | return mService.getCurrentFailedPasswordAttempts(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1790 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1791 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | return -1; |
| 1795 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1796 | |
| 1797 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1798 | * 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] | 1799 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1800 | * @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] | 1801 | * @hide |
| 1802 | */ |
| 1803 | public boolean getDoNotAskCredentialsOnBoot() { |
| 1804 | if (mService != null) { |
| 1805 | try { |
| 1806 | return mService.getDoNotAskCredentialsOnBoot(); |
| 1807 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1808 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | return false; |
| 1812 | } |
| 1813 | |
| 1814 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1815 | * Setting this to a value greater than zero enables a built-in policy |
| 1816 | * that will perform a device wipe after too many incorrect |
| 1817 | * device-unlock passwords have been entered. This built-in policy combines |
| 1818 | * watching for failed passwords and wiping the device, and requires |
| 1819 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1820 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1821 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1822 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1823 | * application only, erasing or revoking credentials, or reporting the |
| 1824 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1825 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1826 | * instead. Do not use this API, because if the maximum count is reached, |
| 1827 | * 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] | 1828 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1829 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1830 | * @param num The number of failed password attempts at which point the |
| 1831 | * device will wipe its data. |
| 1832 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1833 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1834 | if (mService != null) { |
| 1835 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1836 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1837 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1838 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1842 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1843 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1844 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1845 | * 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] | 1846 | * or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1847 | * @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] | 1848 | * all admins. |
| 1849 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1850 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1851 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1855 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1856 | if (mService != null) { |
| 1857 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1858 | return mService.getMaximumFailedPasswordsForWipe( |
| 1859 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1860 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1861 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | return 0; |
| 1865 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1866 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1867 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1868 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1869 | * for the given user. So for primary user, it might return the primary or |
| 1870 | * a managed profile. For a secondary user, it would be the same as the |
| 1871 | * user passed in. |
| 1872 | * @hide Used only by Keyguard |
| 1873 | */ |
| 1874 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1875 | if (mService != null) { |
| 1876 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1877 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 1878 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1879 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1880 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1881 | } |
| 1882 | } |
| 1883 | return UserHandle.USER_NULL; |
| 1884 | } |
| 1885 | |
| 1886 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1887 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1888 | * the password again until the user has entered it. |
| 1889 | */ |
| 1890 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1891 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1892 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1893 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 1894 | * If the flag is set, the device can be booted without asking for user password. |
| 1895 | * The absence of this flag does not change the current boot requirements. This flag |
| 1896 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 1897 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 1898 | * device to factory defaults. |
| 1899 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1900 | 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] | 1901 | |
| 1902 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1903 | * Force a new device unlock password (the password needed to access the |
| 1904 | * entire device, not for individual accounts) on the user. This takes |
| 1905 | * effect immediately. |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 1906 | * |
| 1907 | * <p>Calling this from a managed profile that shares the password with the owner profile |
| 1908 | * will throw a security exception. |
| 1909 | * |
| 1910 | * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
| 1911 | * device admins that are not device owner and not profile owner. |
| 1912 | * The password can now only be changed if there is currently no password set. Device owner |
| 1913 | * and profile owner can still do this.</em> |
| 1914 | * |
| 1915 | * <p>The given password must be sufficient for the |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1916 | * current password quality and length constraints as returned by |
| 1917 | * {@link #getPasswordQuality(ComponentName)} and |
| 1918 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1919 | * these constraints, then it will be rejected and false returned. Note |
| 1920 | * that the password may be a stronger quality (containing alphanumeric |
| 1921 | * characters when the requested quality is only numeric), in which case |
| 1922 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1923 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1924 | * <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] | 1925 | * pattern or password if the current password constraints allow it. <em>Note: This will not |
| 1926 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 1927 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 1928 | * empty, except by device owner or profile owner.</em> |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1929 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1930 | * <p>The calling device admin must have requested |
| 1931 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1932 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1933 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1934 | * @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] | 1935 | * @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] | 1936 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1937 | * @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] | 1938 | * 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] | 1939 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1940 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1941 | if (mParentInstance) { |
| 1942 | throw new SecurityException("Reset password does not work across profiles."); |
| 1943 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1944 | if (mService != null) { |
| 1945 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1946 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1947 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1948 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1949 | } |
| 1950 | } |
| 1951 | return false; |
| 1952 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1953 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1954 | /** |
| 1955 | * Called by an application that is administering the device to set the |
| 1956 | * maximum time for user activity until the device will lock. This limits |
| 1957 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1958 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1959 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1960 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1961 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1962 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1963 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1964 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1965 | * A value of 0 means there is no restriction. |
| 1966 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1967 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1968 | if (mService != null) { |
| 1969 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1970 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1971 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1972 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1973 | } |
| 1974 | } |
| 1975 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1976 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1977 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1978 | * Retrieve the current maximum time to unlock for all admins of this user |
| 1979 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1980 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1981 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 1982 | * @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] | 1983 | * 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] | 1984 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1985 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1986 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1990 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1991 | if (mService != null) { |
| 1992 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1993 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1994 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1995 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1996 | } |
| 1997 | } |
| 1998 | return 0; |
| 1999 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2000 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2001 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2002 | * Make the device lock immediately, as if the lock screen timeout has |
| 2003 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2004 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2005 | * <p>The calling device admin must have requested |
| 2006 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 2007 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2008 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2009 | public void lockNow() { |
| 2010 | if (mService != null) { |
| 2011 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2012 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2013 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2014 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2018 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2019 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2020 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2021 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2022 | */ |
| 2023 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2024 | |
| 2025 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2026 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2027 | * data. |
| 2028 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2029 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2030 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2031 | */ |
| 2032 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2033 | |
| 2034 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 2035 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 2036 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2037 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2038 | * <p>The calling device admin must have requested |
| 2039 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 2040 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2041 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2042 | * @param flags Bit mask of additional options: currently supported flags |
| 2043 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 2044 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2045 | */ |
| 2046 | public void wipeData(int flags) { |
| 2047 | if (mService != null) { |
| 2048 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2049 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2050 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2051 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2055 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2056 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2057 | * Called by an application that is administering the device to set the |
| 2058 | * global proxy and exclusion list. |
| 2059 | * <p> |
| 2060 | * The calling device admin must have requested |
| 2061 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2062 | * this method; if it has not, a security exception will be thrown. |
| 2063 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2064 | * 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] | 2065 | * 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] | 2066 | * be returned. |
| 2067 | * The method can be called repeatedly by the device admin alrady setting the |
| 2068 | * proxy to update the proxy and exclusion list. |
| 2069 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2070 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2071 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2072 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2073 | * @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] | 2074 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2075 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2076 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2077 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2078 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2079 | List<String> exclusionList ) { |
| 2080 | if (proxySpec == null) { |
| 2081 | throw new NullPointerException(); |
| 2082 | } |
| 2083 | if (mService != null) { |
| 2084 | try { |
| 2085 | String hostSpec; |
| 2086 | String exclSpec; |
| 2087 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2088 | hostSpec = null; |
| 2089 | exclSpec = null; |
| 2090 | } else { |
| 2091 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2092 | throw new IllegalArgumentException(); |
| 2093 | } |
| 2094 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2095 | String hostName = sa.getHostName(); |
| 2096 | int port = sa.getPort(); |
| 2097 | StringBuilder hostBuilder = new StringBuilder(); |
| 2098 | hostSpec = hostBuilder.append(hostName) |
| 2099 | .append(":").append(Integer.toString(port)).toString(); |
| 2100 | if (exclusionList == null) { |
| 2101 | exclSpec = ""; |
| 2102 | } else { |
| 2103 | StringBuilder listBuilder = new StringBuilder(); |
| 2104 | boolean firstDomain = true; |
| 2105 | for (String exclDomain : exclusionList) { |
| 2106 | if (!firstDomain) { |
| 2107 | listBuilder = listBuilder.append(","); |
| 2108 | } else { |
| 2109 | firstDomain = false; |
| 2110 | } |
| 2111 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2112 | } |
| 2113 | exclSpec = listBuilder.toString(); |
| 2114 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2115 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2116 | != android.net.Proxy.PROXY_VALID) |
| 2117 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2118 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2119 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2120 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2121 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2122 | } |
| 2123 | } |
| 2124 | return null; |
| 2125 | } |
| 2126 | |
| 2127 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2128 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 2129 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 2130 | * doing something unusual like general internal filtering this may be useful. On |
| 2131 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 2132 | * |
| 2133 | * <p>This method requires the caller to be the device owner. |
| 2134 | * |
| 2135 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 2136 | * @see ProxyInfo |
| 2137 | * |
| 2138 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2139 | * with. |
| 2140 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 2141 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 2142 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2143 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2144 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2145 | if (mService != null) { |
| 2146 | try { |
| 2147 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2148 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2149 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2150 | } |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2155 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2156 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2157 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2158 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2159 | */ |
| 2160 | public ComponentName getGlobalProxyAdmin() { |
| 2161 | if (mService != null) { |
| 2162 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2163 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2164 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2165 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | return null; |
| 2169 | } |
| 2170 | |
| 2171 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2172 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2173 | * indicating that encryption is not supported. |
| 2174 | */ |
| 2175 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2176 | |
| 2177 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2178 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2179 | * indicating that encryption is supported, but is not currently active. |
| 2180 | */ |
| 2181 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2182 | |
| 2183 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2184 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2185 | * indicating that encryption is not currently active, but is currently |
| 2186 | * being activated. This is only reported by devices that support |
| 2187 | * encryption of data and only when the storage is currently |
| 2188 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2189 | * to become encrypted will never return this value. |
| 2190 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2191 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2192 | |
| 2193 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2194 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2195 | * indicating that encryption is active. |
| 2196 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2197 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2198 | |
| 2199 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2200 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2201 | * indicating that encryption is active, but an encryption key has not |
| 2202 | * been set by the user. |
| 2203 | */ |
| 2204 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2205 | |
| 2206 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2207 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2208 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2209 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2210 | * to check encryption status. However, on some devices this activity may never return, as |
| 2211 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2212 | */ |
| 2213 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2214 | public static final String ACTION_START_ENCRYPTION |
| 2215 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2216 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2217 | * Widgets are enabled in keyguard |
| 2218 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2219 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2220 | |
| 2221 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2222 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2223 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2224 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2225 | |
| 2226 | /** |
| 2227 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2228 | */ |
| 2229 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2230 | |
| 2231 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2232 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2233 | */ |
| 2234 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2235 | |
| 2236 | /** |
| 2237 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2238 | */ |
| 2239 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2240 | |
| 2241 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2242 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2243 | * (e.g. PIN/Pattern/Password). |
| 2244 | */ |
| 2245 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2246 | |
| 2247 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2248 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2249 | */ |
| 2250 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2251 | |
| 2252 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2253 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2254 | */ |
| 2255 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2256 | |
| 2257 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2258 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2259 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2260 | * |
| 2261 | * <p>When multiple device administrators attempt to control device |
| 2262 | * encryption, the most secure, supported setting will always be |
| 2263 | * used. If any device administrator requests device encryption, |
| 2264 | * it will be enabled; Conversely, if a device administrator |
| 2265 | * attempts to disable device encryption while another |
| 2266 | * device administrator has enabled it, the call to disable will |
| 2267 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2268 | * |
| 2269 | * <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] | 2270 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2271 | * or control the encryption of any other storage areas. |
| 2272 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2273 | * {@code true}, then the directory returned by |
| 2274 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2275 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2276 | * |
| 2277 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2278 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2279 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2280 | * also require (and check for) a pattern, PIN, or password. |
| 2281 | * |
| 2282 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2283 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2284 | * @return the new request status (for all active admins) - will be one of |
| 2285 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2286 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2287 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2288 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2289 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2290 | if (mService != null) { |
| 2291 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2292 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2293 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2294 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2295 | } |
| 2296 | } |
| 2297 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2298 | } |
| 2299 | |
| 2300 | /** |
| 2301 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2302 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2303 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2304 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2305 | * this will return the requested encryption setting as an aggregate of all active |
| 2306 | * administrators. |
| 2307 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2308 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2309 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2310 | if (mService != null) { |
| 2311 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2312 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2313 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2314 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2315 | } |
| 2316 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2317 | return false; |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Called by an application that is administering the device to |
| 2322 | * determine the current encryption status of the device. |
| 2323 | * |
| 2324 | * Depending on the returned status code, the caller may proceed in different |
| 2325 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2326 | * storage system does not support encryption. If the |
| 2327 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2328 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2329 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2330 | * storage system has enabled encryption but no password is set so further action |
| 2331 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2332 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2333 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2334 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2335 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2336 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2337 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2338 | */ |
| 2339 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2340 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | /** @hide per-user version */ |
| 2344 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2345 | if (mService != null) { |
| 2346 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2347 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2348 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2349 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2350 | } |
| 2351 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2352 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2353 | } |
| 2354 | |
| 2355 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2356 | * Installs the given certificate as a user CA. |
| 2357 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2358 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2359 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2360 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2361 | * |
| 2362 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2363 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2364 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2365 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2366 | if (mService != null) { |
| 2367 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2368 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2369 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2370 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | return false; |
| 2374 | } |
| 2375 | |
| 2376 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2377 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2378 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2379 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2380 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2381 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2382 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2383 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2384 | if (mService != null) { |
| 2385 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2386 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2387 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2388 | } catch (CertificateException e) { |
| 2389 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2390 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2391 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2397 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2398 | * If a user has installed any certificates by other means than device policy these will be |
| 2399 | * included too. |
| 2400 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2401 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2402 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2403 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2404 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2405 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2406 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2407 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2408 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2409 | mService.enforceCanManageCaCerts(admin); |
| 2410 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2411 | for (String alias : certStore.userAliases()) { |
| 2412 | try { |
| 2413 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2414 | } catch (CertificateException ce) { |
| 2415 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2416 | } |
| 2417 | } |
| 2418 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2419 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2426 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2427 | * means other than device policy will also be removed, except for system CA certificates. |
| 2428 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2429 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2430 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2431 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2432 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2433 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2434 | try { |
| 2435 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2436 | .toArray(new String[0])); |
| 2437 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2438 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2439 | } |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | /** |
| 2444 | * Returns whether this certificate is installed as a trusted CA. |
| 2445 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2446 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2447 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2448 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2449 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2450 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2451 | if (mService != null) { |
| 2452 | try { |
| 2453 | mService.enforceCanManageCaCerts(admin); |
| 2454 | return getCaCertAlias(certBuffer) != null; |
| 2455 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2456 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2457 | } catch (CertificateException ce) { |
| 2458 | Log.w(TAG, "Could not parse certificate", ce); |
| 2459 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2460 | } |
| 2461 | return false; |
| 2462 | } |
| 2463 | |
| 2464 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2465 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 2466 | * keypair will be visible to all apps within the profile. |
| 2467 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2468 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2469 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2470 | * @param privKey The private key to install. |
| 2471 | * @param cert The certificate to install. |
| 2472 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2473 | * with that alias already exists, it will be overwritten. |
| 2474 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2475 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2476 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2477 | @NonNull Certificate cert, @NonNull String alias) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2478 | try { |
| 2479 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2480 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2481 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2482 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2483 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2484 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2485 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2486 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2487 | } catch (CertificateException | IOException e) { |
| 2488 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2489 | } |
| 2490 | return false; |
| 2491 | } |
| 2492 | |
| 2493 | /** |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2494 | * Called by a device or profile owner to remove all user credentials installed under a given |
| 2495 | * alias. |
| 2496 | * |
| 2497 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2498 | * {@code null} if calling from a delegated certificate installer. |
| 2499 | * @param alias The private key alias under which the certificate is installed. |
| 2500 | * @return {@code true} if the keys were both removed, {@code false} otherwise. |
| 2501 | */ |
| 2502 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2503 | try { |
| 2504 | return mService.removeKeyPair(admin, alias); |
| 2505 | } catch (RemoteException e) { |
| 2506 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2507 | } |
| 2508 | return false; |
| 2509 | } |
| 2510 | |
| 2511 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2512 | * @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] | 2513 | * doesn't exist. |
| 2514 | */ |
| 2515 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2516 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2517 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2518 | new ByteArrayInputStream(certBuffer)); |
| 2519 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2520 | } |
| 2521 | |
| 2522 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2523 | * 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] | 2524 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2525 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2526 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2527 | * <p> |
| 2528 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2529 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2530 | * installer. |
| 2531 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2532 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2533 | * @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] | 2534 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2535 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2536 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2537 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2538 | if (mService != null) { |
| 2539 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2540 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2541 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2542 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * 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] | 2549 | * user. null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2550 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2551 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2552 | * @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] | 2553 | * if none is set. |
| 2554 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2555 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2556 | if (mService != null) { |
| 2557 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2558 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2559 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2560 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | return null; |
| 2564 | } |
| 2565 | |
| 2566 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2567 | * Called by a device or profile owner to configure an always-on VPN connection through a |
| 2568 | * specific application for the current user. |
| 2569 | * This connection is automatically granted and persisted after a reboot. |
| 2570 | * |
| 2571 | * <p>The designated package should declare a {@link android.net.VpnService} in its |
| 2572 | * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, |
| 2573 | * otherwise the call will fail. |
| 2574 | * |
| 2575 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} |
| 2576 | * to remove an existing always-on VPN configuration. |
| 2577 | * |
| 2578 | * @return {@code true} if the package is set as always-on VPN controller; |
| 2579 | * {@code false} otherwise. |
| 2580 | */ |
| 2581 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2582 | @Nullable String vpnPackage) { |
| 2583 | if (mService != null) { |
| 2584 | try { |
| 2585 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2586 | } catch (RemoteException e) { |
| 2587 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2588 | } |
| 2589 | } |
| 2590 | return false; |
| 2591 | } |
| 2592 | |
| 2593 | /** |
| 2594 | * Called by a device or profile owner to read the name of the package administering an |
| 2595 | * always-on VPN connection for the current user. |
| 2596 | * If there is no such package, or the always-on VPN is provided by the system instead |
| 2597 | * of by an application, {@code null} will be returned. |
| 2598 | * |
| 2599 | * @return Package name of VPN controller responsible for always-on VPN, |
| 2600 | * or {@code null} if none is set. |
| 2601 | */ |
| 2602 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2603 | if (mService != null) { |
| 2604 | try { |
| 2605 | return mService.getAlwaysOnVpnPackage(admin); |
| 2606 | } catch (RemoteException e) { |
| 2607 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2608 | } |
| 2609 | } |
| 2610 | return null; |
| 2611 | } |
| 2612 | |
| 2613 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2614 | * 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] | 2615 | * on the device, for this user. After setting this, no applications running as this user |
| 2616 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2617 | * |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 2618 | * <p>If the caller is device owner, then the restriction will be applied to all users. |
| 2619 | * |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2620 | * <p>The calling device admin must have requested |
| 2621 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2622 | * this method; if it has not, a security exception will be thrown. |
| 2623 | * |
| 2624 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2625 | * @param disabled Whether or not the camera should be disabled. |
| 2626 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2627 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2628 | if (mService != null) { |
| 2629 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2630 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2631 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2632 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2638 | * 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] | 2639 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2640 | * @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] | 2641 | * have disabled the camera |
| 2642 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2643 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2644 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2648 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2649 | if (mService != null) { |
| 2650 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2651 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2652 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2653 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | return false; |
| 2657 | } |
| 2658 | |
| 2659 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2660 | * Called by a device owner to request a bugreport. |
| 2661 | * |
| 2662 | * <p>There must be only one user on the device, managed by the device owner. |
| 2663 | * Otherwise a security exception will be thrown. |
| 2664 | * |
| 2665 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2666 | * @return {@code true} if the bugreport collection started successfully, or {@code false} |
| 2667 | * if it wasn't triggered because a previous bugreport operation is still active |
| 2668 | * (either the bugreport is still running or waiting for the user to share or decline) |
| 2669 | */ |
| 2670 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 2671 | if (mService != null) { |
| 2672 | try { |
| 2673 | return mService.requestBugreport(admin); |
| 2674 | } catch (RemoteException e) { |
| 2675 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2676 | } |
| 2677 | } |
| 2678 | return false; |
| 2679 | } |
| 2680 | |
| 2681 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2682 | * Determine whether or not creating a guest user has been disabled for the device |
| 2683 | * |
| 2684 | * @hide |
| 2685 | */ |
| 2686 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 2687 | // Currently guest users can always be created if multi-user is enabled |
| 2688 | // TODO introduce a policy for guest user creation |
| 2689 | return false; |
| 2690 | } |
| 2691 | |
| 2692 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2693 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2694 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2695 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2696 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2697 | * |
| 2698 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2699 | * security exception will be thrown. |
| 2700 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2701 | * <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] | 2702 | * blocks assist requests for all activities of the relevant user. |
| 2703 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2704 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2705 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2706 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2707 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2708 | if (mService != null) { |
| 2709 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2710 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2711 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2712 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2718 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2719 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2720 | * @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] | 2721 | * have disabled screen capture. |
| 2722 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2723 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2724 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2728 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2729 | if (mService != null) { |
| 2730 | try { |
| 2731 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2732 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2733 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | return false; |
| 2737 | } |
| 2738 | |
| 2739 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2740 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2741 | * required the user cannot set the date and time, but has to use network date and time. |
| 2742 | * |
| 2743 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2744 | * |
| 2745 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2746 | * be thrown. |
| 2747 | * |
| 2748 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2749 | * @param required Whether auto time is set required or not. |
| 2750 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2751 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2752 | if (mService != null) { |
| 2753 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2754 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2755 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2756 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | } |
| 2760 | |
| 2761 | /** |
| 2762 | * @return true if auto time is required. |
| 2763 | */ |
| 2764 | public boolean getAutoTimeRequired() { |
| 2765 | if (mService != null) { |
| 2766 | try { |
| 2767 | return mService.getAutoTimeRequired(); |
| 2768 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2769 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2770 | } |
| 2771 | } |
| 2772 | return false; |
| 2773 | } |
| 2774 | |
| 2775 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 2776 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
| 2777 | * |
| 2778 | * <p>The system user is exempt from this policy - it is never ephemeral. |
| 2779 | * |
| 2780 | * <p>The calling device admin must be the device owner. If it is not, a security exception will |
| 2781 | * be thrown. |
| 2782 | * |
| 2783 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2784 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
| 2785 | * subsequently created users will be ephemeral. |
| 2786 | * @hide |
| 2787 | */ |
| 2788 | public void setForceEphemeralUsers( |
| 2789 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 2790 | if (mService != null) { |
| 2791 | try { |
| 2792 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 2793 | } catch (RemoteException e) { |
| 2794 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2795 | } |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | /** |
| 2800 | * @return true if all users are created ephemeral. |
| 2801 | * @hide |
| 2802 | */ |
| 2803 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 2804 | if (mService != null) { |
| 2805 | try { |
| 2806 | return mService.getForceEphemeralUsers(admin); |
| 2807 | } catch (RemoteException e) { |
| 2808 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2809 | } |
| 2810 | } |
| 2811 | return false; |
| 2812 | } |
| 2813 | |
| 2814 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2815 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2816 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2817 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2818 | * |
| 2819 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2820 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2821 | * this method; if it has not, a security exception will be thrown. |
| 2822 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2823 | * <p>Calling this from a managed profile before version |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2824 | * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2825 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2826 | * <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] | 2827 | * <ul> |
| 2828 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT} |
| 2829 | * these will affect the profile's parent user. |
| 2830 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications |
| 2831 | * generated by applications in the managed profile. |
| 2832 | * </ul> |
| 2833 | * <p>Requests to disable other features on a managed profile will be ignored. The admin |
| 2834 | * can check which features have been disabled by calling |
| 2835 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2836 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2837 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2838 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2839 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2840 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2841 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 2842 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2843 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2844 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2845 | if (mService != null) { |
| 2846 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2847 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2848 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2849 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2850 | } |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2855 | * 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] | 2856 | * admin, if specified, or all admins. |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2857 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 2858 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2859 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2860 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2861 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2862 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2863 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2867 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2868 | if (mService != null) { |
| 2869 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2870 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2871 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2872 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2873 | } |
| 2874 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2875 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2879 | * @hide |
| 2880 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2881 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 2882 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2883 | if (mService != null) { |
| 2884 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2885 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2886 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2887 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2888 | } |
| 2889 | } |
| 2890 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2891 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2892 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2893 | * @hide |
| 2894 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2895 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2896 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2900 | * 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] | 2901 | * @hide |
| 2902 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2903 | public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2904 | ActivityInfo ai; |
| 2905 | try { |
| 2906 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2907 | PackageManager.GET_META_DATA); |
| 2908 | } catch (PackageManager.NameNotFoundException e) { |
| 2909 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2910 | return null; |
| 2911 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2912 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2913 | ResolveInfo ri = new ResolveInfo(); |
| 2914 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2915 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2916 | try { |
| 2917 | return new DeviceAdminInfo(mContext, ri); |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2918 | } catch (XmlPullParserException | IOException e) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2919 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2920 | return null; |
| 2921 | } |
| 2922 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2923 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2924 | /** |
| 2925 | * @hide |
| 2926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2927 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2928 | if (mService != null) { |
| 2929 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2930 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2931 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2932 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2933 | } |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | /** |
| 2938 | * @hide |
| 2939 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2940 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2941 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2942 | if (mService != null) { |
| 2943 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2944 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2945 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2946 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2947 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2951 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2952 | /** |
| 2953 | * @hide |
| 2954 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2955 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2956 | if (mService != null) { |
| 2957 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2958 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2959 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2960 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2964 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2965 | /** |
| 2966 | * @hide |
| 2967 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2968 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2969 | if (mService != null) { |
| 2970 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2971 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2972 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2973 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2977 | |
| 2978 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 2979 | * Should be called when keyguard has been dismissed. |
| 2980 | * @hide |
| 2981 | */ |
| 2982 | public void reportKeyguardDismissed() { |
| 2983 | if (mService != null) { |
| 2984 | try { |
| 2985 | mService.reportKeyguardDismissed(); |
| 2986 | } catch (RemoteException e) { |
| 2987 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2988 | } |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | /** |
| 2993 | * Should be called when keyguard view has been shown to the user. |
| 2994 | * @hide |
| 2995 | */ |
| 2996 | public void reportKeyguardSecured() { |
| 2997 | if (mService != null) { |
| 2998 | try { |
| 2999 | mService.reportKeyguardSecured(); |
| 3000 | } catch (RemoteException e) { |
| 3001 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3002 | } |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3007 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3008 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3009 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3010 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3011 | * @return whether the package was successfully registered as the device owner. |
| 3012 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3013 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3014 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3015 | public boolean setDeviceOwner(ComponentName who) { |
| 3016 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | /** |
| 3020 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3021 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3022 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3023 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | /** |
| 3027 | * @hide |
| 3028 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3029 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3030 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | /** |
| 3034 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3035 | * Sets the given package as the device owner. The package must already be installed. There |
| 3036 | * must not already be a device owner. |
| 3037 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3038 | * this method. |
| 3039 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3040 | * 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] | 3041 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3042 | * @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] | 3043 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3044 | * @return whether the package was successfully registered as the device owner. |
| 3045 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3046 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3047 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3048 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3049 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3050 | if (mService != null) { |
| 3051 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3052 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3053 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3054 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3055 | } |
| 3056 | } |
| 3057 | return false; |
| 3058 | } |
| 3059 | |
| 3060 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3061 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3062 | * 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] | 3063 | * 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] | 3064 | * package is currently registered as the device owner app, pass in the package name from |
| 3065 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3066 | * 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] | 3067 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3068 | * the setup process. |
| 3069 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3070 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3071 | * @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] | 3072 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3073 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3074 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3075 | } |
| 3076 | |
| 3077 | /** |
| 3078 | * @return true if a package is registered as device owner, only when it's running on the |
| 3079 | * calling user. |
| 3080 | * |
| 3081 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3082 | * @hide |
| 3083 | */ |
| 3084 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3085 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3086 | } |
| 3087 | |
| 3088 | /** |
| 3089 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3090 | * user. |
| 3091 | * |
| 3092 | * <p>Requires the MANAGE_USERS permission. |
| 3093 | * |
| 3094 | * @hide |
| 3095 | */ |
| 3096 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3097 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3098 | } |
| 3099 | |
| 3100 | /** |
| 3101 | * @return device owner component name, only when it's running on the calling user. |
| 3102 | * |
| 3103 | * @hide |
| 3104 | */ |
| 3105 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3106 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3107 | } |
| 3108 | |
| 3109 | /** |
| 3110 | * @return device owner component name, even if it's running on a different user. |
| 3111 | * |
| 3112 | * <p>Requires the MANAGE_USERS permission. |
| 3113 | * |
| 3114 | * @hide |
| 3115 | */ |
| 3116 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3117 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3118 | } |
| 3119 | |
| 3120 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3121 | if (packageName == null) { |
| 3122 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3123 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3124 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3125 | if (deviceOwner == null) { |
| 3126 | return false; |
| 3127 | } |
| 3128 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3131 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3132 | if (mService != null) { |
| 3133 | try { |
| 3134 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3135 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3136 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3142 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3143 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3144 | * no device owner. |
| 3145 | * |
| 3146 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3147 | * |
| 3148 | * @hide |
| 3149 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3150 | public int getDeviceOwnerUserId() { |
| 3151 | if (mService != null) { |
| 3152 | try { |
| 3153 | return mService.getDeviceOwnerUserId(); |
| 3154 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3155 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3156 | } |
| 3157 | } |
| 3158 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | /** |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3162 | * Clears the current device owner. The caller must be the device owner. |
| 3163 | * |
| 3164 | * This function should be used cautiously as once it is called it cannot |
| 3165 | * be undone. The device owner can only be set as a part of device setup |
| 3166 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3167 | * |
| 3168 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3169 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3170 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3171 | if (mService != null) { |
| 3172 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3173 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3174 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3175 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3176 | } |
| 3177 | } |
| 3178 | } |
| 3179 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3180 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3181 | * Returns the device owner package name, only if it's running on the calling user. |
| 3182 | * |
| 3183 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3184 | * |
| 3185 | * @hide |
| 3186 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3187 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3188 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3189 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3190 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3194 | * @return true if the device is managed by any device owner. |
| 3195 | * |
| 3196 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3197 | * |
| 3198 | * @hide |
| 3199 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3200 | public boolean isDeviceManaged() { |
| 3201 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3202 | } |
| 3203 | |
| 3204 | /** |
| 3205 | * Returns the device owner name. Note this method *will* return the device owner |
| 3206 | * name when it's running on a different user. |
| 3207 | * |
| 3208 | * <p>Requires the MANAGE_USERS permission. |
| 3209 | * |
| 3210 | * @hide |
| 3211 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3212 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3213 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3214 | if (mService != null) { |
| 3215 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3216 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3217 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3218 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3219 | } |
| 3220 | } |
| 3221 | return null; |
| 3222 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3223 | |
| 3224 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3225 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3226 | * @deprecated Do not use |
| 3227 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3228 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3229 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3230 | @SystemApi |
| 3231 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3232 | return null; |
| 3233 | } |
| 3234 | |
| 3235 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3236 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3237 | * @deprecated Do not use |
| 3238 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3239 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3240 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3241 | @SystemApi |
| 3242 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3243 | return null; |
| 3244 | } |
| 3245 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3246 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3247 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3248 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3249 | * Sets the given component as an active admin and registers the package as the profile |
| 3250 | * owner for this user. The package must already be installed and there shouldn't be |
| 3251 | * an existing profile owner registered for this user. Also, this method must be called |
| 3252 | * before the user setup has been completed. |
| 3253 | * <p> |
| 3254 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3255 | * MANAGE_DEVICE_ADMINS permission. |
| 3256 | * @param admin The component to register as an active admin and profile owner. |
| 3257 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3258 | * @return whether the admin was successfully registered as the profile owner. |
| 3259 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3260 | * the user has already been set up. |
| 3261 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3262 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3263 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3264 | throws IllegalArgumentException { |
| 3265 | if (mService != null) { |
| 3266 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3267 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3268 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3269 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3270 | } catch (RemoteException re) { |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3271 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3272 | } |
| 3273 | } |
| 3274 | return false; |
| 3275 | } |
| 3276 | |
| 3277 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3278 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 3279 | * be from the same package as the active profile owner for this user, otherwise a |
| 3280 | * SecurityException will be thrown. |
| 3281 | * |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3282 | * <p>This doesn't work for managed profile owners. |
| 3283 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3284 | * @param admin The component to remove as the profile owner. |
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 void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3287 | if (mService != null) { |
| 3288 | try { |
| 3289 | mService.clearProfileOwner(admin); |
| 3290 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3291 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3297 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3298 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3299 | */ |
| 3300 | public boolean hasUserSetupCompleted() { |
| 3301 | if (mService != null) { |
| 3302 | try { |
| 3303 | return mService.hasUserSetupCompleted(); |
| 3304 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3305 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } |
| 3308 | return true; |
| 3309 | } |
| 3310 | |
| 3311 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3312 | * @hide |
| 3313 | * 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] | 3314 | * already be installed. There must not already be a profile owner for this user. |
| 3315 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3316 | * this method. |
| 3317 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3318 | * - the caller is SYSTEM_UID. |
| 3319 | * - 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] | 3320 | * @param admin the component name to be registered as profile owner. |
| 3321 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3322 | * @param userHandle the userId to set the profile owner for. |
| 3323 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3324 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3325 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3326 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3327 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3328 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3329 | if (mService != null) { |
| 3330 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3331 | if (ownerName == null) { |
| 3332 | ownerName = ""; |
| 3333 | } |
| 3334 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3335 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3336 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3337 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3338 | } |
| 3339 | } |
| 3340 | return false; |
| 3341 | } |
| 3342 | |
| 3343 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3344 | * Sets the device owner information to be shown on the lock screen. |
| 3345 | * |
| 3346 | * <p>If the device owner information is {@code null} or empty then the device owner info is |
| 3347 | * 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] | 3348 | * <p>If the device owner information contains only whitespaces then the message on the lock |
| 3349 | * 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] | 3350 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 3351 | * <p>If the device owner information needs to be localized, it is the responsibility of the |
| 3352 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3353 | * and set a new version of this string accordingly. |
| 3354 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3355 | * @param admin The name of the admin component to check. |
| 3356 | * @param info Device owner information which will be displayed instead of the user |
| 3357 | * owner info. |
| 3358 | * @return Whether the device owner information has been set. |
| 3359 | */ |
| 3360 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3361 | if (mService != null) { |
| 3362 | try { |
| 3363 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3364 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3365 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3366 | } |
| 3367 | } |
| 3368 | return false; |
| 3369 | } |
| 3370 | |
| 3371 | /** |
| 3372 | * @return The device owner information. If it is not set returns {@code null}. |
| 3373 | */ |
| 3374 | public String getDeviceOwnerLockScreenInfo() { |
| 3375 | if (mService != null) { |
| 3376 | try { |
| 3377 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3378 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3379 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3380 | } |
| 3381 | } |
| 3382 | return null; |
| 3383 | } |
| 3384 | |
| 3385 | /** |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3386 | * Called by device or profile owners for setting the package suspended for this user. |
| 3387 | * A suspended package will not be started by the package manager, its notifications will |
| 3388 | * be hidden and it will not show up in recents. The package must already be installed. |
| 3389 | * |
| 3390 | * @param admin The name of the admin component to check. |
| 3391 | * @param packageName The package name of the app to suspend or unsuspend. |
| 3392 | * @param suspended If set to {@code true} than the package will be suspended, if set to |
| 3393 | * {@code false} the package will be unsuspended. |
| 3394 | * @return boolean {@code true} if the operation was successfully performed, {@code false} |
| 3395 | * otherwise. |
| 3396 | */ |
| 3397 | public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName, |
| 3398 | boolean suspended) { |
| 3399 | if (mService != null) { |
| 3400 | try { |
| 3401 | return mService.setPackageSuspended(admin, packageName, suspended); |
| 3402 | } catch (RemoteException re) { |
| 3403 | Log.w(TAG, "Failed talking with device policy service", re); |
| 3404 | } |
| 3405 | } |
| 3406 | return false; |
| 3407 | } |
| 3408 | |
| 3409 | /** |
| 3410 | * Called by device or profile owners to determine if a package is suspended. |
| 3411 | * |
| 3412 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3413 | * @param packageName The name of the package to retrieve the suspended status of. |
| 3414 | * @return boolean {@code true} if the package is suspended, {@code false} otherwise. |
| 3415 | */ |
| 3416 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3417 | if (mService != null) { |
| 3418 | try { |
| 3419 | return mService.getPackageSuspended(admin, packageName); |
| 3420 | } catch (RemoteException e) { |
| 3421 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3422 | } |
| 3423 | } |
| 3424 | return false; |
| 3425 | } |
| 3426 | |
| 3427 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3428 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3429 | * be used. Only the profile owner can call this. |
| 3430 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3431 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3432 | * |
| 3433 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3434 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3435 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3436 | if (mService != null) { |
| 3437 | try { |
| 3438 | mService.setProfileEnabled(admin); |
| 3439 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3440 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3441 | } |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3446 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3447 | * 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] | 3448 | * never called by the profile or device owner, the name will be set to default values. |
| 3449 | * |
| 3450 | * @see #isProfileOwnerApp |
| 3451 | * @see #isDeviceOwnerApp |
| 3452 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3453 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3454 | * @param profileName The name of the profile. |
| 3455 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3456 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3457 | if (mService != null) { |
| 3458 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3459 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3460 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3461 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3462 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3463 | } |
| 3464 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3465 | |
| 3466 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3467 | * 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] | 3468 | * 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] | 3469 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3470 | * |
| 3471 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3472 | * @return Whether or not the package is registered as the profile owner. |
| 3473 | */ |
| 3474 | public boolean isProfileOwnerApp(String packageName) { |
| 3475 | if (mService != null) { |
| 3476 | try { |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3477 | ComponentName profileOwner = mService.getProfileOwner( |
| 3478 | Process.myUserHandle().getIdentifier()); |
| 3479 | return profileOwner != null |
| 3480 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 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 | } |
| 3484 | } |
| 3485 | return false; |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3490 | * @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] | 3491 | * owner has been set for that user. |
| 3492 | * @throws IllegalArgumentException if the userId is invalid. |
| 3493 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3494 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3495 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3496 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3497 | } |
| 3498 | |
| 3499 | /** |
| 3500 | * @see #getProfileOwner() |
| 3501 | * @hide |
| 3502 | */ |
| 3503 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3504 | if (mService != null) { |
| 3505 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3506 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3507 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3508 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3509 | throw new IllegalArgumentException( |
| 3510 | "Requested profile owner for invalid userId", re); |
| 3511 | } |
| 3512 | } |
| 3513 | return null; |
| 3514 | } |
| 3515 | |
| 3516 | /** |
| 3517 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3518 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3519 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3520 | * @throws IllegalArgumentException if the userId is invalid. |
| 3521 | */ |
| 3522 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3523 | if (mService != null) { |
| 3524 | try { |
| 3525 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3526 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3527 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3528 | throw new IllegalArgumentException( |
| 3529 | "Requested profile owner for invalid userId", re); |
| 3530 | } |
| 3531 | } |
| 3532 | return null; |
| 3533 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3534 | |
| 3535 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3536 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3537 | * @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] | 3538 | * @return the human readable name of the organisation associated with this profile owner or |
| 3539 | * null if one is not set. |
| 3540 | * @throws IllegalArgumentException if the userId is invalid. |
| 3541 | */ |
| 3542 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3543 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3544 | if (mService != null) { |
| 3545 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3546 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3547 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3548 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3549 | throw new IllegalArgumentException( |
| 3550 | "Requested profile owner for invalid userId", re); |
| 3551 | } |
| 3552 | } |
| 3553 | return null; |
| 3554 | } |
| 3555 | |
| 3556 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3557 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3558 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3559 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3560 | * the intent preferences are reset. |
| 3561 | * |
| 3562 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3563 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3564 | * intent handler for the filter. |
| 3565 | * |
| 3566 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3567 | * security exception will be thrown. |
| 3568 | * |
| 3569 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3570 | * @param filter The IntentFilter for which a default handler is added. |
| 3571 | * @param activity The Activity that is added as default intent handler. |
| 3572 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3573 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3574 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3575 | if (mService != null) { |
| 3576 | try { |
| 3577 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3578 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3579 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3580 | } |
| 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | /** |
| 3585 | * 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] | 3586 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3587 | * |
| 3588 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3589 | * exception will be thrown. |
| 3590 | * |
| 3591 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3592 | * @param packageName The name of the package for which preferences are removed. |
| 3593 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3594 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3595 | String packageName) { |
| 3596 | if (mService != null) { |
| 3597 | try { |
| 3598 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3599 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3600 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3604 | |
| 3605 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3606 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 3607 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 3608 | * {@link #getApplicationRestrictions}. |
| 3609 | * <p> |
| 3610 | * This permission is persistent until it is later cleared by calling this method with a |
| 3611 | * {@code null} value or uninstalling the managing package. |
| 3612 | * |
| 3613 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3614 | * @param packageName The package name which will be given access to application restrictions |
| 3615 | * APIs. If {@code null} is given the current package will be cleared. |
| 3616 | */ |
| 3617 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
| 3618 | @Nullable String packageName) { |
| 3619 | if (mService != null) { |
| 3620 | try { |
| 3621 | mService.setApplicationRestrictionsManagingPackage(admin, packageName); |
| 3622 | } catch (RemoteException e) { |
| 3623 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3624 | } |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | /** |
| 3629 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 3630 | * package for the current user, or {@code null} if none is set. |
| 3631 | * |
| 3632 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3633 | * @return The package name allowed to manage application restrictions on the current user, or |
| 3634 | * {@code null} if none is set. |
| 3635 | */ |
| 3636 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 3637 | if (mService != null) { |
| 3638 | try { |
| 3639 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 3640 | } catch (RemoteException e) { |
| 3641 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3642 | } |
| 3643 | } |
| 3644 | return null; |
| 3645 | } |
| 3646 | |
| 3647 | /** |
| 3648 | * Returns {@code true} if the calling package has been granted permission via |
| 3649 | * {@link #setApplicationRestrictionsManagingPackage} to manage application |
| 3650 | * restrictions for the calling user. |
| 3651 | */ |
| 3652 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 3653 | if (mService != null) { |
| 3654 | try { |
| 3655 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 3656 | } catch (RemoteException e) { |
| 3657 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3658 | } |
| 3659 | } |
| 3660 | return false; |
| 3661 | } |
| 3662 | |
| 3663 | /** |
| 3664 | * Sets the application restrictions for a given target application running in the calling user. |
| 3665 | * |
| 3666 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 3667 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 3668 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3669 | * |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 3670 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
| 3671 | * <ul> |
| 3672 | * <li>{@code boolean} |
| 3673 | * <li>{@code int} |
| 3674 | * <li>{@code String} or {@code String[]} |
| 3675 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 3676 | * </ul> |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3677 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3678 | * <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] | 3679 | * the caller can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3680 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 3681 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3682 | * <p>The application restrictions are only made visible to the target application via |
| 3683 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or |
| 3684 | * device owner, and the application restrictions managing package via |
| 3685 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3686 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3687 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3688 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3689 | * @param packageName The name of the package to update restricted settings for. |
| 3690 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 3691 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3692 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3693 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3694 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3695 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3696 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3697 | Bundle settings) { |
| 3698 | if (mService != null) { |
| 3699 | try { |
| 3700 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3701 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3702 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3708 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3709 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3710 | * trust agents but those enabled by this function call. If flag |
| 3711 | * {@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] | 3712 | * |
| 3713 | * <p>The calling device admin must have requested |
| 3714 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3715 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3716 | * |
| 3717 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3718 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3719 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3720 | * will be strictly disabled according to the state of the |
| 3721 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 3722 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 3723 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 3724 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3725 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3726 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 3727 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3728 | if (mService != null) { |
| 3729 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3730 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3731 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3732 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | } |
| 3736 | |
| 3737 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3738 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 3739 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 3740 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3741 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3742 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3743 | * this function returns a list of configurations for all admins that declare |
| 3744 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 3745 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 3746 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 3747 | * 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] | 3748 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3749 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3750 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3751 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3752 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3753 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3757 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3758 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3759 | if (mService != null) { |
| 3760 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3761 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3762 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3763 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3764 | } |
| 3765 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3766 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3770 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 3771 | * 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] | 3772 | * |
| 3773 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3774 | * security exception will be thrown. |
| 3775 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3776 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3777 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 3778 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3779 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3780 | if (mService != null) { |
| 3781 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3782 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3783 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3784 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3785 | } |
| 3786 | } |
| 3787 | } |
| 3788 | |
| 3789 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3790 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 3791 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3792 | * |
| 3793 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3794 | * security exception will be thrown. |
| 3795 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3796 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3797 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3798 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3799 | if (mService != null) { |
| 3800 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3801 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3802 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3803 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | return false; |
| 3807 | } |
| 3808 | |
| 3809 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3810 | * Determine whether or not caller-Id information has been disabled. |
| 3811 | * |
| 3812 | * @param userHandle The user for whom to check the caller-id permission |
| 3813 | * @hide |
| 3814 | */ |
| 3815 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 3816 | if (mService != null) { |
| 3817 | try { |
| 3818 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 3819 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3820 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3821 | } |
| 3822 | } |
| 3823 | return false; |
| 3824 | } |
| 3825 | |
| 3826 | /** |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 3827 | * Called by a profile owner of a managed profile to set whether contacts search from |
| 3828 | * the managed profile will be shown in the parent profile, for incoming calls. |
| 3829 | * |
| 3830 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3831 | * security exception will be thrown. |
| 3832 | * |
| 3833 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3834 | * @param disabled If true contacts search in the managed profile is not displayed. |
| 3835 | */ |
| 3836 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 3837 | boolean disabled) { |
| 3838 | if (mService != null) { |
| 3839 | try { |
| 3840 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 3841 | } catch (RemoteException e) { |
| 3842 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3843 | } |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | /** |
| 3848 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 3849 | * has been disabled. |
| 3850 | * |
| 3851 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3852 | * security exception will be thrown. |
| 3853 | * |
| 3854 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3855 | */ |
| 3856 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 3857 | if (mService != null) { |
| 3858 | try { |
| 3859 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 3860 | } catch (RemoteException e) { |
| 3861 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3862 | } |
| 3863 | } |
| 3864 | return false; |
| 3865 | } |
| 3866 | |
| 3867 | |
| 3868 | /** |
| 3869 | * Determine whether or not contacts search has been disabled. |
| 3870 | * |
| 3871 | * @param userHandle The user for whom to check the contacts search permission |
| 3872 | * @hide |
| 3873 | */ |
| 3874 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 3875 | if (mService != null) { |
| 3876 | try { |
| 3877 | return mService |
| 3878 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 3879 | } catch (RemoteException e) { |
| 3880 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3881 | } |
| 3882 | } |
| 3883 | return false; |
| 3884 | } |
| 3885 | |
| 3886 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3887 | * 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] | 3888 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3889 | * @hide |
| 3890 | */ |
| 3891 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3892 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3893 | if (mService != null) { |
| 3894 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3895 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 3896 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3897 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3898 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3899 | } |
| 3900 | } |
| 3901 | } |
| 3902 | |
| 3903 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3904 | * 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] | 3905 | * @hide |
| 3906 | */ |
| 3907 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 3908 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3909 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 3910 | originalIntent); |
| 3911 | } |
| 3912 | |
| 3913 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3914 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 3915 | * devices can access enterprise contacts. |
| 3916 | * <p> |
| 3917 | * The calling device admin must be a profile owner. If it is not, a |
| 3918 | * security exception will be thrown. |
| 3919 | * <p> |
| 3920 | * This API works on managed profile only. |
| 3921 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3922 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3923 | * with. |
| 3924 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 3925 | * contacts. |
| 3926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3927 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3928 | if (mService != null) { |
| 3929 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3930 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3931 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3932 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | } |
| 3936 | |
| 3937 | /** |
| 3938 | * Called by a profile owner of a managed profile to determine whether or |
| 3939 | * not Bluetooth devices cannot access enterprise contacts. |
| 3940 | * <p> |
| 3941 | * The calling device admin must be a profile owner. If it is not, a |
| 3942 | * security exception will be thrown. |
| 3943 | * <p> |
| 3944 | * This API works on managed profile only. |
| 3945 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3946 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3947 | * with. |
| 3948 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3949 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3950 | if (mService != null) { |
| 3951 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3952 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3953 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3954 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3955 | } |
| 3956 | } |
| 3957 | return true; |
| 3958 | } |
| 3959 | |
| 3960 | /** |
| 3961 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 3962 | * <p> |
| 3963 | * This API works on managed profile UserHandle only. |
| 3964 | * |
| 3965 | * @param userHandle The user for whom to check the caller-id permission |
| 3966 | * @hide |
| 3967 | */ |
| 3968 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 3969 | if (mService != null) { |
| 3970 | try { |
| 3971 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 3972 | .getIdentifier()); |
| 3973 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3974 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3975 | } |
| 3976 | } |
| 3977 | return true; |
| 3978 | } |
| 3979 | |
| 3980 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3981 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 3982 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 3983 | * Only activity intents are supported. |
| 3984 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3985 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3986 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 3987 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 3988 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 3989 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3990 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3991 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3992 | if (mService != null) { |
| 3993 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3994 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3995 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3996 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3997 | } |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4002 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4003 | * 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] | 4004 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4005 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4006 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4007 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4008 | if (mService != null) { |
| 4009 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4010 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4011 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4012 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4013 | } |
| 4014 | } |
| 4015 | } |
| 4016 | |
| 4017 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4018 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 4019 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4020 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 4021 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4022 | * By default the user can use any accessiblity service. When zero or more packages have |
| 4023 | * 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] | 4024 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4025 | * |
| 4026 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 4027 | * can be used, calling with an empty list only allows the builtin system's services. |
| 4028 | * |
| 4029 | * <p> System accesibility services are always available to the user the list can't modify |
| 4030 | * this. |
| 4031 | * |
| 4032 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4033 | * @param packageNames List of accessibility service package names. |
| 4034 | * |
| 4035 | * @return true if setting the restriction succeeded. It fail if there is |
| 4036 | * one or more non-system accessibility services enabled, that are not in the list. |
| 4037 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4038 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4039 | List<String> packageNames) { |
| 4040 | if (mService != null) { |
| 4041 | try { |
| 4042 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4043 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4044 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4045 | } |
| 4046 | } |
| 4047 | return false; |
| 4048 | } |
| 4049 | |
| 4050 | /** |
| 4051 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 4052 | * |
| 4053 | * <p>An empty list means no accessibility services except system services are allowed. |
| 4054 | * Null means all accessibility services are allowed. |
| 4055 | * |
| 4056 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4057 | * @return List of accessiblity service package names. |
| 4058 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4059 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4060 | if (mService != null) { |
| 4061 | try { |
| 4062 | return mService.getPermittedAccessibilityServices(admin); |
| 4063 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4064 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4065 | } |
| 4066 | } |
| 4067 | return null; |
| 4068 | } |
| 4069 | |
| 4070 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame^] | 4071 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4072 | * |
| 4073 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4074 | * @param packageName Accessibility service package name that needs to be checked. |
| 4075 | * @param userHandle user id the admin is running as. |
| 4076 | * @return true if the accessibility service is permitted, otherwise false. |
| 4077 | * |
| 4078 | * @hide |
| 4079 | */ |
| 4080 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4081 | @NonNull String packageName, int userHandle) { |
| 4082 | if (mService != null) { |
| 4083 | try { |
| 4084 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4085 | userHandle); |
| 4086 | } catch (RemoteException e) { |
| 4087 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4088 | } |
| 4089 | } |
| 4090 | return false; |
| 4091 | } |
| 4092 | |
| 4093 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4094 | * Returns the list of accessibility services permitted by the device or profiles |
| 4095 | * owners of this user. |
| 4096 | * |
| 4097 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4098 | * it will contain the intersection of the permitted lists for any device or profile |
| 4099 | * owners that apply to this user. It will also include any system accessibility services. |
| 4100 | * |
| 4101 | * @param userId which user to check for. |
| 4102 | * @return List of accessiblity service package names. |
| 4103 | * @hide |
| 4104 | */ |
| 4105 | @SystemApi |
| 4106 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4107 | if (mService != null) { |
| 4108 | try { |
| 4109 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4110 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4111 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4112 | } |
| 4113 | } |
| 4114 | return null; |
| 4115 | } |
| 4116 | |
| 4117 | /** |
| 4118 | * Called by a profile or device owner to set the permitted input methods services. When |
| 4119 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4120 | * user the device owner or profile owner is an admin for. |
| 4121 | * |
| 4122 | * By default the user can use any input method. When zero or more packages have |
| 4123 | * been added, input method that are not in the list and not part of the system |
| 4124 | * can not be enabled by the user. |
| 4125 | * |
| 4126 | * This method will fail if it is called for a admin that is not for the foreground user |
| 4127 | * or a profile of the foreground user. |
| 4128 | * |
| 4129 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 4130 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 4131 | * |
| 4132 | * <p> System input methods are always available to the user this method can't modify this. |
| 4133 | * |
| 4134 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4135 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 4136 | * @return true if setting the restriction succeeded. It will fail if there are |
| 4137 | * one or more non-system input methods currently enabled that are not in |
| 4138 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4139 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4140 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4141 | if (mService != null) { |
| 4142 | try { |
| 4143 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4144 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4145 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4146 | } |
| 4147 | } |
| 4148 | return false; |
| 4149 | } |
| 4150 | |
| 4151 | |
| 4152 | /** |
| 4153 | * Returns the list of permitted input methods set by this device or profile owner. |
| 4154 | * |
| 4155 | * <p>An empty list means no input methods except system input methods are allowed. |
| 4156 | * Null means all input methods are allowed. |
| 4157 | * |
| 4158 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4159 | * @return List of input method package names. |
| 4160 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4161 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4162 | if (mService != null) { |
| 4163 | try { |
| 4164 | return mService.getPermittedInputMethods(admin); |
| 4165 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4166 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | return null; |
| 4170 | } |
| 4171 | |
| 4172 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame^] | 4173 | * Called by the system to check if a specific input method is disabled by admin. |
| 4174 | * |
| 4175 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4176 | * @param packageName Input method package name that needs to be checked. |
| 4177 | * @param userHandle user id the admin is running as. |
| 4178 | * @return true if the input method is permitted, otherwise false. |
| 4179 | * |
| 4180 | * @hide |
| 4181 | */ |
| 4182 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4183 | @NonNull String packageName, int userHandle) { |
| 4184 | if (mService != null) { |
| 4185 | try { |
| 4186 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4187 | } catch (RemoteException e) { |
| 4188 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4189 | } |
| 4190 | } |
| 4191 | return false; |
| 4192 | } |
| 4193 | |
| 4194 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4195 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4196 | * 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] | 4197 | * |
| 4198 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4199 | * it will contain the intersection of the permitted lists for any device or profile |
| 4200 | * owners that apply to this user. It will also include any system input methods. |
| 4201 | * |
| 4202 | * @return List of input method package names. |
| 4203 | * @hide |
| 4204 | */ |
| 4205 | @SystemApi |
| 4206 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4207 | if (mService != null) { |
| 4208 | try { |
| 4209 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4210 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4211 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4212 | } |
| 4213 | } |
| 4214 | return null; |
| 4215 | } |
| 4216 | |
| 4217 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4218 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4219 | * currently installed it. |
| 4220 | * |
| 4221 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4222 | * |
| 4223 | * @return List of package names to keep cached. |
| 4224 | * @hide |
| 4225 | */ |
| 4226 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4227 | if (mService != null) { |
| 4228 | try { |
| 4229 | return mService.getKeepUninstalledPackages(admin); |
| 4230 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4231 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4232 | } |
| 4233 | } |
| 4234 | return null; |
| 4235 | } |
| 4236 | |
| 4237 | /** |
| 4238 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4239 | * currently installed it. |
| 4240 | * |
| 4241 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4242 | * automatically pre-cached.</p> |
| 4243 | * |
| 4244 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4245 | * @param packageNames List of package names to keep cached. |
| 4246 | * @hide |
| 4247 | */ |
| 4248 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4249 | @NonNull List<String> packageNames) { |
| 4250 | if (mService != null) { |
| 4251 | try { |
| 4252 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4253 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4254 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4255 | } |
| 4256 | } |
| 4257 | } |
| 4258 | |
| 4259 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4260 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4261 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4262 | * created. If you need to persist an identifier for this user, use |
| 4263 | * {@link UserManager#getSerialNumberForUser}. |
| 4264 | * |
| 4265 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4266 | * @param name the user's name |
| 4267 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4268 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4269 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4270 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4271 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4272 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4273 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4274 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4275 | try { |
| 4276 | return mService.createUser(admin, name); |
| 4277 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4278 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4279 | } |
| 4280 | return null; |
| 4281 | } |
| 4282 | |
| 4283 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4284 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4285 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4286 | * created. If you need to persist an identifier for this user, use |
| 4287 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4288 | * immediately. |
| 4289 | * |
| 4290 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4291 | * as registered as an active admin on the new user. The profile owner package will be |
| 4292 | * installed on the new user if it already is installed on the device. |
| 4293 | * |
| 4294 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4295 | * profileOwnerComponent when onEnable is called. |
| 4296 | * |
| 4297 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4298 | * @param name the user's name |
| 4299 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4300 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4301 | * the user. |
| 4302 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4303 | * on the new user. |
| 4304 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4305 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4306 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4307 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4308 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4309 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4310 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4311 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4312 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4313 | try { |
| 4314 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 4315 | adminExtras); |
| 4316 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4317 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4318 | } |
| 4319 | return null; |
| 4320 | } |
| 4321 | |
| 4322 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4323 | * 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] | 4324 | */ |
| 4325 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4326 | |
| 4327 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4328 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4329 | * ephemeral. |
| 4330 | * @hide |
| 4331 | */ |
| 4332 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4333 | |
| 4334 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4335 | * Called by a device owner to create a user with the specified name and a given component of |
| 4336 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4337 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4338 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4339 | * user will not be started in the background. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4340 | * |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4341 | * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also |
| 4342 | * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and |
| 4343 | * will be registered as an active admin on the new user. The profile owner package will be |
| 4344 | * installed on the new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4345 | * |
| 4346 | * <p>If the adminExtras are not null, they will be stored on the device until the user is |
| 4347 | * started for the first time. Then the extras will be passed to the admin when |
| 4348 | * onEnable is called. |
| 4349 | * |
| 4350 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4351 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4352 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
| 4353 | * same package as admin, otherwise no user is created and an IllegalArgumentException is |
| 4354 | * thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4355 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
| 4356 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4357 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4358 | * @see UserHandle |
| 4359 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4360 | * user could not be created. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4361 | */ |
| 4362 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4363 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4364 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4365 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4366 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4367 | } catch (RemoteException re) { |
| 4368 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 4369 | } |
| 4370 | return null; |
| 4371 | } |
| 4372 | |
| 4373 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4374 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 4375 | * not be removed. |
| 4376 | * |
| 4377 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4378 | * @param userHandle the user to remove. |
| 4379 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 4380 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4381 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4382 | try { |
| 4383 | return mService.removeUser(admin, userHandle); |
| 4384 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4385 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4386 | return false; |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4391 | * Called by a device owner to switch the specified user to the foreground. |
| 4392 | * |
| 4393 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4394 | * @param userHandle the user to switch to; null will switch to primary. |
| 4395 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 4396 | * |
| 4397 | * @see Intent#ACTION_USER_FOREGROUND |
| 4398 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4399 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4400 | try { |
| 4401 | return mService.switchUser(admin, userHandle); |
| 4402 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4403 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4404 | return false; |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4409 | * Retrieves the application restrictions for a given target application running in the calling |
| 4410 | * user. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4411 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4412 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4413 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4414 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4415 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4416 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4417 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4418 | * @param packageName The name of the package to fetch restricted settings of. |
| 4419 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 4420 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 4421 | * if no restrictions have been set. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4422 | * |
| 4423 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4424 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4425 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4426 | if (mService != null) { |
| 4427 | try { |
| 4428 | return mService.getApplicationRestrictions(admin, packageName); |
| 4429 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4430 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4431 | } |
| 4432 | } |
| 4433 | return null; |
| 4434 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4435 | |
| 4436 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4437 | * 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] | 4438 | * <p> |
| 4439 | * The calling device admin must be a profile or device owner; if it is not, |
| 4440 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4441 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4442 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4443 | * with. |
| 4444 | * @param key The key of the restriction. See the constants in |
| 4445 | * {@link android.os.UserManager} for the list of keys. |
| 4446 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4447 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4448 | if (mService != null) { |
| 4449 | try { |
| 4450 | mService.setUserRestriction(admin, key, true); |
| 4451 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4452 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4453 | } |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4458 | * 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] | 4459 | * <p> |
| 4460 | * The calling device admin must be a profile or device owner; if it is not, |
| 4461 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4462 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4463 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4464 | * with. |
| 4465 | * @param key The key of the restriction. See the constants in |
| 4466 | * {@link android.os.UserManager} for the list of keys. |
| 4467 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4468 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4469 | if (mService != null) { |
| 4470 | try { |
| 4471 | mService.setUserRestriction(admin, key, false); |
| 4472 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4473 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4474 | } |
| 4475 | } |
| 4476 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4477 | |
| 4478 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4479 | * Called by a profile or device owner to get user restrictions set with |
| 4480 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4481 | * <p> |
| 4482 | * The target user may have more restrictions set by the system or other device owner / profile |
| 4483 | * owner. To get all the user restrictions currently set, use |
| 4484 | * {@link UserManager#getUserRestrictions()}. |
| 4485 | * |
| 4486 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4487 | * @throws SecurityException if the {@code admin} is not an active admin. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4488 | */ |
| 4489 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4490 | return getUserRestrictions(admin, myUserId()); |
| 4491 | } |
| 4492 | |
| 4493 | /** @hide per-user version */ |
| 4494 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4495 | Bundle ret = null; |
| 4496 | if (mService != null) { |
| 4497 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4498 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4499 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4500 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | return ret == null ? new Bundle() : ret; |
| 4504 | } |
| 4505 | |
| 4506 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4507 | * 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] | 4508 | * is unavailable for use, but the data and actual package file remain. |
| 4509 | * |
| 4510 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4511 | * @param packageName The name of the package to hide or unhide. |
| 4512 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 4513 | * unhidden. |
| 4514 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4515 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4516 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4517 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4518 | if (mService != null) { |
| 4519 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4520 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4521 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4522 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4523 | } |
| 4524 | } |
| 4525 | return false; |
| 4526 | } |
| 4527 | |
| 4528 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4529 | * 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] | 4530 | * |
| 4531 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4532 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4533 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4534 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4535 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4536 | if (mService != null) { |
| 4537 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4538 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4539 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4540 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4541 | } |
| 4542 | } |
| 4543 | return false; |
| 4544 | } |
| 4545 | |
| 4546 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4547 | * 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] | 4548 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4549 | * |
| 4550 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4551 | * @param packageName The package to be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4552 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4553 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4554 | if (mService != null) { |
| 4555 | try { |
| 4556 | mService.enableSystemApp(admin, packageName); |
| 4557 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4558 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4559 | } |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4564 | * 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] | 4565 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4566 | * |
| 4567 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4568 | * @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] | 4569 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4570 | * @return int The number of activities that matched the intent and were installed. |
| 4571 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4572 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4573 | if (mService != null) { |
| 4574 | try { |
| 4575 | return mService.enableSystemAppWithIntent(admin, intent); |
| 4576 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4577 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4578 | } |
| 4579 | } |
| 4580 | return 0; |
| 4581 | } |
| 4582 | |
| 4583 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4584 | * Called by a device owner or profile owner to disable account management for a specific type |
| 4585 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4586 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4587 | * <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] | 4588 | * security exception will be thrown. |
| 4589 | * |
| 4590 | * <p>When account management is disabled for an account type, adding or removing an account |
| 4591 | * of that type will not be possible. |
| 4592 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 4593 | * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
| 4594 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 4595 | * management for a specific type is disabled. |
| 4596 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4597 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4598 | * @param accountType For which account management is disabled or enabled. |
| 4599 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 4600 | * enabled (false). |
| 4601 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4602 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4603 | boolean disabled) { |
| 4604 | if (mService != null) { |
| 4605 | try { |
| 4606 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 4607 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4608 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4609 | } |
| 4610 | } |
| 4611 | } |
| 4612 | |
| 4613 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4614 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 4615 | * |
| 4616 | * <p> Account management can be disabled/enabled by calling |
| 4617 | * {@link #setAccountManagementDisabled}. |
| 4618 | * |
| 4619 | * @return a list of account types for which account management has been disabled. |
| 4620 | * |
| 4621 | * @see #setAccountManagementDisabled |
| 4622 | */ |
| 4623 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4624 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
| 4628 | * @see #getAccountTypesWithManagementDisabled() |
| 4629 | * @hide |
| 4630 | */ |
| 4631 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4632 | if (mService != null) { |
| 4633 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4634 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4635 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4636 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | |
| 4640 | return null; |
| 4641 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4642 | |
| 4643 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4644 | * Sets which packages may enter lock task mode. |
| 4645 | * |
| 4646 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 4647 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4648 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4649 | * 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] | 4650 | * package list results in locked tasks belonging to those packages to be finished. |
| 4651 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 4652 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4653 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4654 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4655 | * |
| 4656 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 4657 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 4658 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 4659 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4660 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4661 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4662 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4663 | if (mService != null) { |
| 4664 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4665 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4666 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4667 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4668 | } |
| 4669 | } |
| 4670 | } |
| 4671 | |
| 4672 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4673 | * 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] | 4674 | * |
| 4675 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4676 | * @hide |
| 4677 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4678 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4679 | if (mService != null) { |
| 4680 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4681 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4682 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4683 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | return null; |
| 4687 | } |
| 4688 | |
| 4689 | /** |
| 4690 | * This function lets the caller know whether the given component is allowed to start the |
| 4691 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4692 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4693 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4694 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4695 | if (mService != null) { |
| 4696 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4697 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4698 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4699 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | return false; |
| 4703 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4704 | |
| 4705 | /** |
| 4706 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 4707 | * 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] | 4708 | * <p>The settings that can be updated with this method are: |
| 4709 | * <ul> |
| 4710 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 4711 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 4712 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4713 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4714 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4715 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 4716 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4717 | * 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] | 4718 | * 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] | 4719 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4720 | * 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] | 4721 | * </li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4722 | * </ul> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4723 | * <p>Changing the following settings has no effect as of |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4724 | * {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4725 | * <ul> |
| 4726 | * <li>{@link Settings.Global#BLUETOOTH_ON}. |
| 4727 | * Use {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 4728 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
| 4729 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 4730 | * <li>{@link Settings.Global#MODE_RINGER}. |
| 4731 | * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
| 4732 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 4733 | * <li>{@link Settings.Global#WIFI_ON}. |
| 4734 | * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
| 4735 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4736 | * |
| 4737 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4738 | * @param setting The name of the setting to update. |
| 4739 | * @param value The value to update the setting to. |
| 4740 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4741 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4742 | if (mService != null) { |
| 4743 | try { |
| 4744 | mService.setGlobalSetting(admin, setting, value); |
| 4745 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4746 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4747 | } |
| 4748 | } |
| 4749 | } |
| 4750 | |
| 4751 | /** |
| 4752 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 4753 | * that the value of the setting is in the correct form for the setting type should be performed |
| 4754 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4755 | * <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] | 4756 | * <ul> |
| 4757 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 4758 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4759 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 4760 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4761 | * <p>A device owner can additionally update the following settings: |
| 4762 | * <ul> |
| 4763 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 4764 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4765 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4766 | * @param setting The name of the setting to update. |
| 4767 | * @param value The value to update the setting to. |
| 4768 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4769 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4770 | if (mService != null) { |
| 4771 | try { |
| 4772 | mService.setSecureSetting(admin, setting, value); |
| 4773 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4774 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | } |
| 4778 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4779 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4780 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4781 | * making permission requests of a local or remote administrator of the user. |
| 4782 | * <p/> |
| 4783 | * Only a profile owner can designate the restrictions provider. |
| 4784 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4785 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 4786 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4787 | * it removes the restrictions provider previously assigned. |
| 4788 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4789 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 4790 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4791 | if (mService != null) { |
| 4792 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4793 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4794 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4795 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4796 | } |
| 4797 | } |
| 4798 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4799 | |
| 4800 | /** |
| 4801 | * Called by profile or device owners to set the master volume mute on or off. |
| 4802 | * |
| 4803 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4804 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 4805 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4806 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4807 | if (mService != null) { |
| 4808 | try { |
| 4809 | mService.setMasterVolumeMuted(admin, on); |
| 4810 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4811 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4812 | } |
| 4813 | } |
| 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 4818 | * |
| 4819 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4820 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 4821 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4822 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4823 | if (mService != null) { |
| 4824 | try { |
| 4825 | return mService.isMasterVolumeMuted(admin); |
| 4826 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4827 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4828 | } |
| 4829 | } |
| 4830 | return false; |
| 4831 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4832 | |
| 4833 | /** |
| 4834 | * Called by profile or device owners to change whether a user can uninstall |
| 4835 | * a package. |
| 4836 | * |
| 4837 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4838 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4839 | * @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] | 4840 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4841 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4842 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4843 | if (mService != null) { |
| 4844 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4845 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4846 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4847 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4848 | } |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4853 | * 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] | 4854 | * 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] | 4855 | * <p> |
| 4856 | * <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] | 4857 | * 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] | 4858 | * 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] | 4859 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4860 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4861 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 4862 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4863 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 4864 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4865 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4866 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4867 | if (mService != null) { |
| 4868 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 4869 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4870 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4871 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4872 | } |
| 4873 | } |
| 4874 | return false; |
| 4875 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4876 | |
| 4877 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4878 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 4879 | * 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] | 4880 | * 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] | 4881 | * 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] | 4882 | * a package may have zero or more provider components, where each component |
| 4883 | * provides a different widget type. |
| 4884 | * <p> |
| 4885 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4886 | * |
| 4887 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4888 | * @param packageName The package from which widget providers are white-listed. |
| 4889 | * @return Whether the package was added. |
| 4890 | * |
| 4891 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4892 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4893 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4894 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4895 | if (mService != null) { |
| 4896 | try { |
| 4897 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 4898 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4899 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4900 | } |
| 4901 | } |
| 4902 | return false; |
| 4903 | } |
| 4904 | |
| 4905 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4906 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 4907 | * 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] | 4908 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 4909 | * android.content.ComponentName, String)}. |
| 4910 | * <p> |
| 4911 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4912 | * |
| 4913 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4914 | * @param packageName The package from which widget providers are no longer |
| 4915 | * white-listed. |
| 4916 | * @return Whether the package was removed. |
| 4917 | * |
| 4918 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4919 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4920 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4921 | public boolean removeCrossProfileWidgetProvider( |
| 4922 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4923 | if (mService != null) { |
| 4924 | try { |
| 4925 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 4926 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4927 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4928 | } |
| 4929 | } |
| 4930 | return false; |
| 4931 | } |
| 4932 | |
| 4933 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4934 | * 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] | 4935 | * available in the parent profile. |
| 4936 | * |
| 4937 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4938 | * @return The white-listed package list. |
| 4939 | * |
| 4940 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4941 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4942 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4943 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4944 | if (mService != null) { |
| 4945 | try { |
| 4946 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 4947 | if (providers != null) { |
| 4948 | return providers; |
| 4949 | } |
| 4950 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4951 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4952 | } |
| 4953 | } |
| 4954 | return Collections.emptyList(); |
| 4955 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4956 | |
| 4957 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4958 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4959 | * |
| 4960 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4961 | * @param icon the bitmap to set as the photo. |
| 4962 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4963 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4964 | try { |
| 4965 | mService.setUserIcon(admin, icon); |
| 4966 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4967 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4968 | } |
| 4969 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 4970 | |
| 4971 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4972 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 4973 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4974 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4975 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 4976 | * components in the device owner package can set system update policies and the |
| 4977 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4978 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4979 | * @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] | 4980 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4981 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4982 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4983 | if (mService != null) { |
| 4984 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4985 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4986 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4987 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4988 | } |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4993 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4994 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4995 | * @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] | 4996 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4997 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4998 | if (mService != null) { |
| 4999 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5000 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5001 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5002 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5003 | } |
| 5004 | } |
| 5005 | return null; |
| 5006 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5007 | |
| 5008 | /** |
| 5009 | * Called by a device owner to disable the keyguard altogether. |
| 5010 | * |
| 5011 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 5012 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 5013 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 5014 | * being disabled. |
| 5015 | * |
| 5016 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5017 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5018 | * |
| 5019 | * @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] | 5020 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5021 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5022 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5023 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5024 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5025 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5026 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5027 | return false; |
| 5028 | } |
| 5029 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5030 | |
| 5031 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5032 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 5033 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5034 | * a single use device. |
| 5035 | * |
| 5036 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5037 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 5038 | * |
| 5039 | * @return {@code false} if attempting to disable the status bar failed. |
| 5040 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5041 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5042 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5043 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5044 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [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); |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5047 | return false; |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5048 | } |
| 5049 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5050 | |
| 5051 | /** |
| 5052 | * Callable by the system update service to notify device owners about pending updates. |
| 5053 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5054 | * permission. |
| 5055 | * |
| 5056 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5057 | * when the current pending update was first available. -1 if no update is available. |
| 5058 | * @hide |
| 5059 | */ |
| 5060 | @SystemApi |
| 5061 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5062 | if (mService != null) { |
| 5063 | try { |
| 5064 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5065 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5066 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5070 | |
| 5071 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5072 | * Called by profile or device owners to set the default response for future runtime permission |
| 5073 | * requests by applications. The policy can allow for normal operation which prompts the |
| 5074 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 5075 | * 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] | 5076 | * updates. When a permission is denied or granted this way, the effect is equivalent to setting |
| 5077 | * the permission grant state via {@link #setPermissionGrantState}. |
| 5078 | * |
| 5079 | * <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] | 5080 | * 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] | 5081 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5082 | * @param admin Which profile or device owner this request is associated with. |
| 5083 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 5084 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5085 | * |
| 5086 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5087 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5088 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5089 | try { |
| 5090 | mService.setPermissionPolicy(admin, policy); |
| 5091 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5092 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | |
| 5096 | /** |
| 5097 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5098 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5099 | * @param admin Which profile or device owner this request is associated with. |
| 5100 | * @return the current policy for future permission requests. |
| 5101 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5102 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5103 | try { |
| 5104 | return mService.getPermissionPolicy(admin); |
| 5105 | } catch (RemoteException re) { |
| 5106 | return PERMISSION_POLICY_PROMPT; |
| 5107 | } |
| 5108 | } |
| 5109 | |
| 5110 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5111 | * Sets the grant state of a runtime permission for a specific application. The state |
| 5112 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 5113 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 5114 | * is denied and the user cannot manage it through the UI, and {@link |
| 5115 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 5116 | * user cannot manage it through the UI. This might affect all permissions in a |
| 5117 | * group that the runtime permission belongs to. This method can only be called |
| 5118 | * by a profile or device owner. |
| 5119 | * |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5120 | * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not |
| 5121 | * revoke the permission. It retains the previous grant, if any. |
| 5122 | * |
| 5123 | * <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] | 5124 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5125 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5126 | * @param admin Which profile or device owner this request is associated with. |
| 5127 | * @param packageName The application to grant or revoke a permission to. |
| 5128 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5129 | * @param grantState The permission grant state which is one of {@link |
| 5130 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5131 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5132 | * @return whether the permission was successfully granted or revoked. |
| 5133 | * |
| 5134 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5135 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5136 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5137 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5138 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5139 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5140 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5141 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5142 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5143 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5144 | return false; |
| 5145 | } |
| 5146 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5147 | |
| 5148 | /** |
| 5149 | * Returns the current grant state of a runtime permission for a specific application. |
| 5150 | * |
| 5151 | * @param admin Which profile or device owner this request is associated with. |
| 5152 | * @param packageName The application to check the grant state for. |
| 5153 | * @param permission The permission to check for. |
| 5154 | * @return the current grant state specified by device policy. If the profile or device owner |
| 5155 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 5156 | * This does not indicate whether or not the permission is currently granted for the package. |
| 5157 | * |
| 5158 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 5159 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5160 | * which indicates if the permission is currently denied or granted. |
| 5161 | * |
| 5162 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5163 | * @see PackageManager#checkPermission(String, String) |
| 5164 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5165 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5166 | String permission) { |
| 5167 | try { |
| 5168 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5169 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5170 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5171 | return PERMISSION_GRANT_STATE_DEFAULT; |
| 5172 | } |
| 5173 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5174 | |
| 5175 | /** |
| 5176 | * Returns if provisioning a managed profile or device is possible or not. |
| 5177 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5178 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 5179 | * Note that even if this method returns true, there is a slight possibility that the |
| 5180 | * provisioning will not be allowed when it is actually initiated because some event has |
| 5181 | * happened in between. |
| 5182 | * @return if provisioning a managed profile or device is possible or not. |
| 5183 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5184 | */ |
| 5185 | public boolean isProvisioningAllowed(String action) { |
| 5186 | try { |
| 5187 | return mService.isProvisioningAllowed(action); |
| 5188 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5189 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5190 | return false; |
| 5191 | } |
| 5192 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5193 | |
| 5194 | /** |
| 5195 | * @hide |
| 5196 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5197 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5198 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5199 | * @param admin Which profile owner this request is associated with. |
| 5200 | * @return if this user is a managed profile of another user. |
| 5201 | */ |
| 5202 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5203 | try { |
| 5204 | return mService.isManagedProfile(admin); |
| 5205 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5206 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5207 | return false; |
| 5208 | } |
| 5209 | } |
| 5210 | |
| 5211 | /** |
| 5212 | * @hide |
| 5213 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5214 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5215 | * @param admin Which device owner this request is associated with. |
| 5216 | * @return if this user is a system-only user. |
| 5217 | */ |
| 5218 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5219 | try { |
| 5220 | return mService.isSystemOnlyUser(admin); |
| 5221 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5222 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5223 | return false; |
| 5224 | } |
| 5225 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5226 | |
| 5227 | /** |
| 5228 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5229 | * |
| 5230 | * @return the MAC address of the Wi-Fi device, or null when the information is not |
| 5231 | * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5232 | * |
| 5233 | * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5234 | */ |
| 5235 | public String getWifiMacAddress() { |
| 5236 | try { |
| 5237 | return mService.getWifiMacAddress(); |
| 5238 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5239 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5240 | return null; |
| 5241 | } |
| 5242 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5243 | |
| 5244 | /** |
| 5245 | * Called by device owner to reboot the device. |
| 5246 | */ |
| 5247 | public void reboot(@NonNull ComponentName admin) { |
| 5248 | try { |
| 5249 | mService.reboot(admin); |
| 5250 | } catch (RemoteException re) { |
| 5251 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5252 | } |
| 5253 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5254 | |
| 5255 | /** |
| 5256 | * Called by a device admin to set the short support message. This will |
| 5257 | * be displayed to the user in settings screens where funtionality has |
| 5258 | * been disabled by the admin. |
| 5259 | * |
| 5260 | * The message should be limited to a short statement such as |
| 5261 | * "This setting is disabled by your administrator. Contact someone@example.com |
| 5262 | * for support." |
| 5263 | * If the message is longer than 200 characters it may be truncated. |
| 5264 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5265 | * <p>If the short support message needs to be localized, it is the responsibility of the |
| 5266 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5267 | * and set a new version of this string accordingly. |
| 5268 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5269 | * @see #setLongSupportMessage |
| 5270 | * |
| 5271 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5272 | * @param message Short message to be displayed to the user in settings or null to |
| 5273 | * clear the existing message. |
| 5274 | */ |
| 5275 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5276 | @Nullable String message) { |
| 5277 | if (mService != null) { |
| 5278 | try { |
| 5279 | mService.setShortSupportMessage(admin, message); |
| 5280 | } catch (RemoteException e) { |
| 5281 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5282 | } |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | /** |
| 5287 | * Called by a device admin to get the short support message. |
| 5288 | * |
| 5289 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5290 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5291 | * or null if no message has been set. |
| 5292 | */ |
| 5293 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5294 | if (mService != null) { |
| 5295 | try { |
| 5296 | return mService.getShortSupportMessage(admin); |
| 5297 | } catch (RemoteException e) { |
| 5298 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5299 | } |
| 5300 | } |
| 5301 | return null; |
| 5302 | } |
| 5303 | |
| 5304 | /** |
| 5305 | * Called by a device admin to set the long support message. This will |
| 5306 | * be displayed to the user in the device administators settings screen. |
| 5307 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5308 | * <p>If the long support message needs to be localized, it is the responsibility of the |
| 5309 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5310 | * and set a new version of this string accordingly. |
| 5311 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5312 | * @see #setShortSupportMessage |
| 5313 | * |
| 5314 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5315 | * @param message Long message to be displayed to the user in settings or null to |
| 5316 | * clear the existing message. |
| 5317 | */ |
| 5318 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5319 | @Nullable String message) { |
| 5320 | if (mService != null) { |
| 5321 | try { |
| 5322 | mService.setLongSupportMessage(admin, message); |
| 5323 | } catch (RemoteException e) { |
| 5324 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5325 | } |
| 5326 | } |
| 5327 | } |
| 5328 | |
| 5329 | /** |
| 5330 | * Called by a device admin to get the long support message. |
| 5331 | * |
| 5332 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5333 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5334 | * or null if no message has been set. |
| 5335 | */ |
| 5336 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5337 | if (mService != null) { |
| 5338 | try { |
| 5339 | return mService.getLongSupportMessage(admin); |
| 5340 | } catch (RemoteException e) { |
| 5341 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5342 | } |
| 5343 | } |
| 5344 | return null; |
| 5345 | } |
| 5346 | |
| 5347 | /** |
| 5348 | * Called by the system to get the short support message. |
| 5349 | * |
| 5350 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5351 | * @param userHandle user id the admin is running as. |
| 5352 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5353 | * |
| 5354 | * @hide |
| 5355 | */ |
| 5356 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5357 | if (mService != null) { |
| 5358 | try { |
| 5359 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5360 | } catch (RemoteException e) { |
| 5361 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5362 | } |
| 5363 | } |
| 5364 | return null; |
| 5365 | } |
| 5366 | |
| 5367 | |
| 5368 | /** |
| 5369 | * Called by the system to get the long support message. |
| 5370 | * |
| 5371 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5372 | * @param userHandle user id the admin is running as. |
| 5373 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5374 | * |
| 5375 | * @hide |
| 5376 | */ |
| 5377 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5378 | if (mService != null) { |
| 5379 | try { |
| 5380 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5381 | } catch (RemoteException e) { |
| 5382 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5383 | } |
| 5384 | } |
| 5385 | return null; |
| 5386 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5387 | |
| 5388 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5389 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5390 | * whose calls act on the parent profile. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5391 | * |
| 5392 | * <p> Note only some methods will work on the parent Manager. |
| 5393 | * |
| 5394 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
| 5395 | */ |
| 5396 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5397 | try { |
| 5398 | if (!mService.isManagedProfile(admin)) { |
| 5399 | throw new SecurityException("The current user does not have a parent profile."); |
| 5400 | } |
| 5401 | return new DevicePolicyManager(mContext, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5402 | } catch (RemoteException e) { |
| 5403 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5404 | return null; |
| 5405 | } |
| 5406 | } |
| 5407 | |
| 5408 | /** |
| 5409 | * Called by device owner to control the device logging feature. Logging can only be |
| 5410 | * enabled on single user devices where the sole user is managed by the device owner. |
| 5411 | * |
| 5412 | * <p> Device logs contain various information intended for security auditing purposes. |
| 5413 | * See {@link SecurityEvent} for details. |
| 5414 | * |
| 5415 | * @param admin Which device owner this request is associated with. |
| 5416 | * @param enabled whether device logging should be enabled or not. |
| 5417 | * @see #retrieveDeviceLogs |
| 5418 | */ |
| 5419 | public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 5420 | try { |
| 5421 | mService.setDeviceLoggingEnabled(admin, enabled); |
| 5422 | } catch (RemoteException re) { |
| 5423 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | /** |
| 5428 | * Return whether device logging is enabled or not by the device owner. |
| 5429 | * |
| 5430 | * @param admin Which device owner this request is associated with. |
| 5431 | * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise. |
| 5432 | */ |
| 5433 | public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) { |
| 5434 | try { |
| 5435 | return mService.getDeviceLoggingEnabled(admin); |
| 5436 | } catch (RemoteException re) { |
| 5437 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5438 | return false; |
| 5439 | } |
| 5440 | } |
| 5441 | |
| 5442 | /** |
| 5443 | * Called by device owner to retrieve all new device logging entries since the last call to |
| 5444 | * this API after device boots. |
| 5445 | * |
| 5446 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 5447 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 5448 | * |
| 5449 | * @param admin Which device owner this request is associated with. |
| 5450 | * @return the new batch of device logs which is a list of {@link SecurityEvent}, |
| 5451 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
| 5452 | */ |
| 5453 | public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) { |
| 5454 | try { |
| 5455 | ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin); |
| 5456 | if (list != null) { |
| 5457 | return list.getList(); |
| 5458 | } else { |
| 5459 | // Rate limit exceeded. |
| 5460 | return null; |
| 5461 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5462 | } catch (RemoteException re) { |
| 5463 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5464 | return null; |
| 5465 | } |
| 5466 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5467 | |
| 5468 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 5469 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 5470 | * profile. |
| 5471 | * |
| 5472 | * @hide |
| 5473 | */ |
| 5474 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 5475 | mContext.checkSelfPermission( |
| 5476 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 5477 | if (!uInfo.isManagedProfile()) { |
| 5478 | throw new SecurityException("The user " + uInfo.id |
| 5479 | + " does not have a parent profile."); |
| 5480 | } |
| 5481 | return new DevicePolicyManager(mContext, true); |
| 5482 | } |
| 5483 | |
| 5484 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5485 | * Called by device owners to retrieve device logs from before the device's last reboot. |
| 5486 | * |
| 5487 | * <p> |
| 5488 | * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be |
| 5489 | * corruption-free during power cycles, due to hardware variations and limitations. As a |
| 5490 | * result, this API is provided as best-effort and the returned logs may contain corrupted data. |
| 5491 | * </strong> |
| 5492 | * |
| 5493 | * @param admin Which device owner this request is associated with. |
| 5494 | * @return Device logs from before the latest reboot of the system. |
| 5495 | */ |
| 5496 | public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) { |
| 5497 | try { |
| 5498 | ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin); |
| 5499 | return list.getList(); |
| 5500 | } catch (RemoteException re) { |
| 5501 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5502 | return Collections.<SecurityEvent>emptyList(); |
| 5503 | } |
| 5504 | } |
| 5505 | |
| 5506 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5507 | * Called by a profile owner of a managed profile to set the color used for customization. |
| 5508 | * This color is used as background color of the confirm credentials screen for that user. |
| 5509 | * The default color is {@link android.graphics.Color#GRAY}. |
| 5510 | * |
| 5511 | * <p>The confirm credentials screen can be created using |
| 5512 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5513 | * |
| 5514 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5515 | * @param color The 32bit representation of the color to be used. |
| 5516 | */ |
| 5517 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5518 | try { |
| 5519 | mService.setOrganizationColor(admin, color); |
| 5520 | } catch (RemoteException re) { |
| 5521 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | /** |
| 5526 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5527 | * This color is used as background color of the confirm credentials screen for that user. |
| 5528 | * |
| 5529 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5530 | * @return The 32bit representation of the color to be used. |
| 5531 | */ |
| 5532 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 5533 | try { |
| 5534 | return mService.getOrganizationColor(admin); |
| 5535 | } catch (RemoteException re) { |
| 5536 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5537 | return 0; |
| 5538 | } |
| 5539 | } |
| 5540 | |
| 5541 | /** |
| 5542 | * @hide |
| 5543 | * Retrieve the customization color for a given user. |
| 5544 | * |
| 5545 | * @param userHandle The user id of the user we're interested in. |
| 5546 | * @return The 32bit representation of the color to be used. |
| 5547 | */ |
| 5548 | public int getOrganizationColorForUser(int userHandle) { |
| 5549 | try { |
| 5550 | return mService.getOrganizationColorForUser(userHandle); |
| 5551 | } catch (RemoteException re) { |
| 5552 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5553 | return 0; |
| 5554 | } |
| 5555 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5556 | |
| 5557 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5558 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 5559 | * management. |
| 5560 | * |
| 5561 | * <p>If the organization name needs to be localized, it is the responsibility of the |
| 5562 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5563 | * and set a new version of this string accordingly. |
| 5564 | * |
| 5565 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5566 | * @param title The organization name or {@code null} to clear a previously set name. |
| 5567 | */ |
| 5568 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 5569 | try { |
| 5570 | mService.setOrganizationName(admin, title); |
| 5571 | } catch (RemoteException re) { |
| 5572 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | /** |
| 5577 | * Called by a profile owner of a managed profile to retrieve the name of the organization |
| 5578 | * under management. |
| 5579 | * |
| 5580 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5581 | * @return The organization name or {@code null} if none is set. |
| 5582 | */ |
| 5583 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 5584 | try { |
| 5585 | return mService.getOrganizationName(admin); |
| 5586 | } catch (RemoteException re) { |
| 5587 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5588 | return null; |
| 5589 | } |
| 5590 | } |
| 5591 | |
| 5592 | /** |
| 5593 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 5594 | * |
| 5595 | * @param userHandle The user id of the user we're interested in. |
| 5596 | * @return The organization name or {@code null} if none is set. |
| 5597 | * |
| 5598 | * @hide |
| 5599 | */ |
| 5600 | public String getOrganizationNameForUser(int userHandle) { |
| 5601 | try { |
| 5602 | return mService.getOrganizationNameForUser(userHandle); |
| 5603 | } catch (RemoteException re) { |
| 5604 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5605 | return null; |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5610 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 5611 | * return {@link #STATE_USER_UNMANAGED} |
| 5612 | * @hide |
| 5613 | */ |
| 5614 | @UserProvisioningState |
| 5615 | public int getUserProvisioningState() { |
| 5616 | if (mService != null) { |
| 5617 | try { |
| 5618 | return mService.getUserProvisioningState(); |
| 5619 | } catch (RemoteException e) { |
| 5620 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5621 | } |
| 5622 | } |
| 5623 | return STATE_USER_UNMANAGED; |
| 5624 | } |
| 5625 | |
| 5626 | /** |
| 5627 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 5628 | * |
| 5629 | * @param state to store |
| 5630 | * @param userHandle for user |
| 5631 | * @hide |
| 5632 | */ |
| 5633 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 5634 | if (mService != null) { |
| 5635 | try { |
| 5636 | mService.setUserProvisioningState(state, userHandle); |
| 5637 | } catch (RemoteException e) { |
| 5638 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5639 | } |
| 5640 | } |
| 5641 | } |
| 5642 | |
| 5643 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5644 | * @hide |
| 5645 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 5646 | * affiliated if it is managed by the same entity as the device. |
| 5647 | * |
| 5648 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 5649 | * user/profile is considered affiliated if the following conditions are both met: |
| 5650 | * <ul> |
| 5651 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 5652 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 5653 | * and a profile owner intersect, they must have come from the same source, which means that |
| 5654 | * the device owner and profile owner are controlled by the same entity.</li> |
| 5655 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 5656 | * </ul> |
| 5657 | * |
| 5658 | * @param admin Which profile or device owner this request is associated with. |
| 5659 | * @param ids A set of opaque affiliation ids. |
| 5660 | */ |
| 5661 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 5662 | try { |
| 5663 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 5664 | } catch (RemoteException e) { |
| 5665 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5666 | } |
| 5667 | } |
| 5668 | |
| 5669 | /** |
| 5670 | * @hide |
| 5671 | * Returns whether this user/profile is affiliated with the device. See |
| 5672 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 5673 | * |
| 5674 | * @return whether this user/profile is affiliated with the device. |
| 5675 | */ |
| 5676 | public boolean isAffiliatedUser() { |
| 5677 | try { |
| 5678 | return mService != null && mService.isAffiliatedUser(); |
| 5679 | } catch (RemoteException e) { |
| 5680 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5681 | return false; |
| 5682 | } |
| 5683 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5684 | } |