Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 23 | import android.annotation.SdkConstant; |
| 24 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 26 | import android.annotation.UserIdInt; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 27 | import android.app.Activity; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 28 | import android.auditing.SecurityLog; |
| 29 | import android.auditing.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 30 | import android.content.ComponentName; |
| 31 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 32 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 33 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.PackageManager; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 36 | import android.content.pm.ParceledListSlice; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 37 | import android.content.pm.ResolveInfo; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 38 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 39 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 40 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 41 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 42 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 43 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 44 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 45 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 46 | import android.os.RemoteException; |
| 47 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 48 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 49 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 50 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 51 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 52 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 53 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 54 | import android.util.Log; |
| 55 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 56 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 57 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 58 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 59 | import org.xmlpull.v1.XmlPullParserException; |
| 60 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 61 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 62 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 63 | import java.lang.annotation.Retention; |
| 64 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 65 | import java.net.InetSocketAddress; |
| 66 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 67 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 68 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 69 | import java.security.PrivateKey; |
| 70 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 71 | import java.security.cert.CertificateException; |
| 72 | import java.security.cert.CertificateFactory; |
| 73 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 74 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 75 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 76 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 77 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 78 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 79 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 82 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 83 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 84 | * <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] | 85 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 86 | * accessible to all device administrators unless the documentation for that method specifies that |
| 87 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 88 | * |
| 89 | * <div class="special reference"> |
| 90 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 91 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 92 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 93 | * developer guide. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 94 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 95 | */ |
| 96 | public class DevicePolicyManager { |
| 97 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | |
| 99 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 100 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 101 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 102 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 103 | private static final String REMOTE_EXCEPTION_MESSAGE = |
| 104 | "Failed to talk with device policy manager service"; |
| 105 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 106 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 107 | this(context, |
| 108 | IDevicePolicyManager.Stub.asInterface( |
| 109 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 110 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 113 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 114 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 115 | protected DevicePolicyManager( |
| 116 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | mContext = context; |
| 118 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 119 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** @hide */ |
| 123 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 124 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 125 | return me.mService != null ? me : null; |
| 126 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 127 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 128 | /** @hide test will override it. */ |
| 129 | @VisibleForTesting |
| 130 | protected int myUserId() { |
| 131 | return UserHandle.myUserId(); |
| 132 | } |
| 133 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 134 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 135 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 136 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 137 | * <p>A managed profile allows data separation for example for the usage of a |
| 138 | * device as a personal and corporate device. The user which provisioning is started from and |
| 139 | * the managed profile share a launcher. |
| 140 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 141 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 142 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 143 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 144 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 145 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 146 | * {@link #isProvisioningAllowed(String)}. |
| 147 | * |
| 148 | * <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] | 149 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 150 | * 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] | 151 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 152 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 153 | * |
| 154 | * <p> The intent may also contain the following extras: |
| 155 | * <ul> |
| 156 | * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li> |
| 157 | * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li> |
| 158 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 159 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 160 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 161 | * in the provisioning intent. The |
| 162 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 163 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 164 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 165 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 166 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 167 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 168 | * |
| 169 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 170 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 171 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 172 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 173 | * 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] | 174 | */ |
| 175 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 176 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 177 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 178 | |
| 179 | /** |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 180 | * @hide |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 181 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 182 | * |
| 183 | * <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] | 184 | * 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] | 185 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 186 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 187 | * allowed. |
| 188 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 189 | * <p>This intent should contain the extra |
| 190 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 191 | * |
| 192 | * <p> If provisioning fails, the device returns to its previous state. |
| 193 | * |
| 194 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 195 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 196 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 197 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 198 | * 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] | 199 | */ |
| 200 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 201 | public static final String ACTION_PROVISION_MANAGED_USER |
| 202 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 203 | |
| 204 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 205 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 206 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 207 | * |
| 208 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 209 | * A device owner has full control over the device. The device owner can not be modified by the |
| 210 | * user. |
| 211 | * |
| 212 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 213 | * employee or client. |
| 214 | * |
| 215 | * <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] | 216 | * It is possible to check if provisioning is allowed or not by querying the method |
| 217 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 218 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 219 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 220 | * <ul> |
| 221 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 222 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 223 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 224 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 225 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 226 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 227 | * </ul> |
| 228 | * |
| 229 | * <p> When device owner provisioning has completed, an intent of the type |
| 230 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 231 | * device owner. |
| 232 | * |
| 233 | * <p> If provisioning fails, the device is factory reset. |
| 234 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 235 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 236 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 237 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 238 | * 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] | 239 | */ |
| 240 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 241 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 242 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 243 | |
| 244 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 245 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 246 | * |
| 247 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 248 | * the device. A device owner has full control over the device. The device owner can not be |
| 249 | * modified by the user and the only way of resetting the device is via factory reset. |
| 250 | * |
| 251 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 252 | * employee or client. |
| 253 | * |
| 254 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 255 | * |
| 256 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 257 | * by a privileged app with the permission |
| 258 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 259 | * |
| 260 | * <p>The provisioning intent contains the following properties: |
| 261 | * <ul> |
| 262 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 278 | * |
| 279 | * @hide |
| 280 | */ |
| 281 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 282 | @SystemApi |
| 283 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 284 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 285 | |
| 286 | /** |
| 287 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 288 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 289 | * |
| 290 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 291 | * management state that is distinct from that reached by |
| 292 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 293 | * user, and only has control over device-wide policies, not individual users and their data. |
| 294 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 295 | * this form of device management. |
| 296 | * |
| 297 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 298 | * A device owner has full control over the device. The device owner can not be modified by the |
| 299 | * user. |
| 300 | * |
| 301 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 302 | * employee or client. |
| 303 | * |
| 304 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 305 | * It is possible to check if provisioning is allowed or not by querying the method |
| 306 | * {@link #isProvisioningAllowed(String)}. |
| 307 | * |
| 308 | * <p>The intent contains the following extras: |
| 309 | * <ul> |
| 310 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 312 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 314 | * </ul> |
| 315 | * |
| 316 | * <p> When device owner provisioning has completed, an intent of the type |
| 317 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 318 | * device owner. |
| 319 | * |
| 320 | * <p> If provisioning fails, the device is factory reset. |
| 321 | * |
| 322 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 323 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 324 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 325 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 326 | * |
| 327 | * @hide |
| 328 | */ |
| 329 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 330 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 331 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 332 | |
| 333 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 334 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 335 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 336 | * <ul> |
| 337 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 338 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 339 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 340 | * </ul> |
| 341 | * |
| 342 | * @hide |
| 343 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 344 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 345 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 346 | public static final String ACTION_PROVISION_FINALIZATION |
| 347 | = "android.app.action.PROVISION_FINALIZATION"; |
| 348 | |
| 349 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 350 | * 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] | 351 | * allows a mobile device management application or NFC programmer application which starts |
| 352 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 353 | * <p> |
| 354 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 355 | * sends the intent to pass data to itself on the newly created profile. |
| 356 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 357 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 358 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 359 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 360 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 361 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 362 | * management application after provisioning. |
| 363 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 364 | * <p> |
| 365 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 366 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 367 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 368 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 369 | */ |
| 370 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 371 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 372 | |
| 373 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 374 | * A String extra holding the package name of the mobile device management application that |
| 375 | * will be set as the profile owner or device owner. |
| 376 | * |
| 377 | * <p>If an application starts provisioning directly via an intent with action |
| 378 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 379 | * application that started provisioning. The package will be set as profile owner in that case. |
| 380 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 381 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 382 | * 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] | 383 | * |
| 384 | * <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] | 385 | * 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] | 386 | |
| 387 | * @see DeviceAdminReceiver |
| 388 | * @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] | 389 | * supported, but only if there is only one device admin receiver in the package that requires |
| 390 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 391 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 392 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 393 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 394 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 395 | |
| 396 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 397 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 398 | * application that will be set as the profile owner or device owner and active admin. |
| 399 | * |
| 400 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 401 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 402 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 403 | * 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] | 404 | * |
| 405 | * <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] | 406 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 407 | * message containing an NFC record with MIME type |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 408 | * {@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] | 409 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 410 | * |
| 411 | * @see DeviceAdminReceiver |
| 412 | */ |
| 413 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 414 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 415 | |
| 416 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 417 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 418 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 419 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 420 | * |
| 421 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 422 | */ |
| 423 | |
| 424 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 425 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 426 | |
| 427 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 428 | * A String extra that, holds the email address of the account which a managed profile is |
| 429 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 430 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 431 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 432 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 433 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 434 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 435 | * contains this extra, it is forwarded in the |
| 436 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 437 | * device management application that was set as the profile owner during provisioning. |
| 438 | * 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] | 439 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 440 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 441 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 442 | |
| 443 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 444 | * A integer extra indicating the predominant color to show during the provisioning. |
| 445 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 446 | * |
| 447 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 448 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 449 | */ |
| 450 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 451 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 452 | |
| 453 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 454 | * 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] | 455 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 456 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 457 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 458 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 459 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 460 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 461 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 462 | |
| 463 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 464 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 465 | * will be set to. |
| 466 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 467 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 468 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 469 | */ |
| 470 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 471 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 472 | |
| 473 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 474 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 475 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 476 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 477 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 478 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 479 | */ |
| 480 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 481 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 482 | |
| 483 | /** |
| 484 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 485 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 486 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 487 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 488 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 489 | */ |
| 490 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 491 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 492 | |
| 493 | /** |
| 494 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 495 | * owner provisioning for downloading the mobile device management application. |
| 496 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 497 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 498 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 499 | */ |
| 500 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 501 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 505 | * is hidden or not. |
| 506 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 507 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 508 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 509 | */ |
| 510 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 511 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 512 | |
| 513 | /** |
| 514 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 515 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 516 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 517 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 518 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 519 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 520 | */ |
| 521 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 522 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 523 | |
| 524 | /** |
| 525 | * A String extra holding the password of the wifi network in |
| 526 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 527 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 528 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 529 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 530 | */ |
| 531 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 532 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 533 | |
| 534 | /** |
| 535 | * A String extra holding the proxy host for the wifi network in |
| 536 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 537 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 538 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 539 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 540 | */ |
| 541 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 542 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 543 | |
| 544 | /** |
| 545 | * An int extra holding the proxy port for the wifi network in |
| 546 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 547 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 548 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 549 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 550 | */ |
| 551 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 552 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 553 | |
| 554 | /** |
| 555 | * A String extra holding the proxy bypass for the wifi network in |
| 556 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 557 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 558 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 559 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 560 | */ |
| 561 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 562 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 566 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 567 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 568 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 569 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 570 | */ |
| 571 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 572 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 573 | |
| 574 | /** |
| 575 | * A String extra holding a url that specifies the download location of the device admin |
| 576 | * package. When not provided it is assumed that the device admin package is already installed. |
| 577 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 578 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 579 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 580 | */ |
| 581 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 582 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 583 | |
| 584 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 585 | * An int extra holding a minimum required version code for the device admin package. If the |
| 586 | * device admin is already installed on the device, it will only be re-downloaded from |
| 587 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 588 | * installed package is less than this version code. |
| 589 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 590 | * <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] | 591 | * provisioning via an NFC bump. |
| 592 | */ |
| 593 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 594 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 595 | |
| 596 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 597 | * A String extra holding a http cookie header which should be used in the http request to the |
| 598 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 599 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 600 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 601 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 602 | */ |
| 603 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 604 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 605 | |
| 606 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 607 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 608 | * the file at download location specified in |
| 609 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 610 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 611 | * <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] | 612 | * present. The provided checksum should match the checksum of the file at the download |
| 613 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 614 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 615 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 616 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 617 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 618 | * |
| 619 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 620 | * 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] | 621 | * 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] | 622 | * 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] | 623 | */ |
| 624 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 625 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 626 | |
| 627 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 628 | * 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] | 629 | * android package archive at the download location specified in {@link |
| 630 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 631 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 632 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 633 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 634 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 635 | * |
| 636 | * <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] | 637 | * 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] | 638 | * the download location. If the checksum does not match an error will be shown to the user and |
| 639 | * the user will be asked to factory reset the device. |
| 640 | * |
| 641 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 642 | * provisioning via an NFC bump. |
| 643 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 644 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 645 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 646 | |
| 647 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 648 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 649 | * has completed successfully. |
| 650 | * |
| 651 | * <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] | 652 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 653 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 654 | * <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] | 655 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 656 | */ |
| 657 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 658 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 659 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 660 | |
| 661 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 662 | * 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] | 663 | * provisioning. |
| 664 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 665 | * <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] | 666 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 667 | */ |
| 668 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 669 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 670 | |
| 671 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 672 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 673 | * provisioning. If this extra is not passed, a default image will be shown. |
| 674 | * <h5>The following URI schemes are accepted:</h5> |
| 675 | * <ul> |
| 676 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 677 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 678 | * </ul> |
| 679 | * |
| 680 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 681 | * pixed density for the device. |
| 682 | * |
| 683 | * <p> If a content: URI is passed, the intent should have the flag |
| 684 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 685 | * {@link android.content.ClipData} of the intent too. |
| 686 | * |
| 687 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 688 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 689 | */ |
| 690 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 691 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 692 | |
| 693 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 694 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 695 | * during setup-wizard. |
| 696 | * |
| 697 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 698 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 699 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 700 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 701 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 702 | * |
| 703 | * @hide |
| 704 | */ |
| 705 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 706 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 707 | |
| 708 | /** |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 709 | * This MIME type is used for starting the Device Owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 710 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 711 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 712 | * A device owner has full control over the device. The device owner can not be modified by the |
| 713 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 714 | * reset. |
| 715 | * |
| 716 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 717 | * employee or client. |
| 718 | * |
| 719 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 720 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 721 | * <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] | 722 | * contains the following properties: |
| 723 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 724 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 725 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 726 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 727 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 728 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 729 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 730 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 731 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 732 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 733 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 734 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 735 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 736 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 737 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 738 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 739 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 740 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 741 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 742 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 743 | * 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] | 744 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 745 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 746 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 747 | */ |
| 748 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 749 | = "application/com.android.managedprovisioning"; |
| 750 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 751 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 752 | * Activity action: ask the user to add a new device administrator to the system. |
| 753 | * The desired policy is the ComponentName of the policy in the |
| 754 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 755 | * bring the user through adding the device administrator to the system (or |
| 756 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 757 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 758 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 759 | * field to provide the user with additional explanation (in addition |
| 760 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 761 | * |
| 762 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 763 | * user intervention). However, if your administrator has been updated and is requesting |
| 764 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 765 | * 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] | 766 | */ |
| 767 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 768 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 769 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 770 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 771 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 772 | * @hide |
| 773 | * 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] | 774 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 775 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 776 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 777 | * 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] | 778 | * to remotely control restrictions on the user. |
| 779 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 780 | * <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] | 781 | * result of whether or not the user approved the action. If approved, the result will |
| 782 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 783 | * as a profile owner. |
| 784 | * |
| 785 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 786 | * field to provide the user with additional explanation (in addition |
| 787 | * to your component's description) about what is being added. |
| 788 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 789 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 790 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 791 | */ |
| 792 | @SystemApi |
| 793 | public static final String ACTION_SET_PROFILE_OWNER |
| 794 | = "android.app.action.SET_PROFILE_OWNER"; |
| 795 | |
| 796 | /** |
| 797 | * @hide |
| 798 | * Name of the profile owner admin that controls the user. |
| 799 | */ |
| 800 | @SystemApi |
| 801 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 802 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 803 | |
| 804 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 805 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 806 | * 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] | 807 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 808 | * @hide |
| 809 | */ |
| 810 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 811 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 812 | |
| 813 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 814 | * Broadcast action: sent when the device owner is set or changed. |
| 815 | * |
| 816 | * This broadcast is sent only to the primary user. |
| 817 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 818 | */ |
| 819 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 820 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 821 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 822 | |
| 823 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 824 | * The ComponentName of the administrator component. |
| 825 | * |
| 826 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 827 | */ |
| 828 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 829 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 830 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 831 | * An optional CharSequence providing additional explanation for why the |
| 832 | * admin is being added. |
| 833 | * |
| 834 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 835 | */ |
| 836 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 837 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 838 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 839 | * Activity action: have the user enter a new password. This activity should |
| 840 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 841 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 842 | * enter a new password that meets the current requirements. You can use |
| 843 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 844 | * have the user select a new password in order to meet the current |
| 845 | * constraints. Upon being resumed from this activity, you can check the new |
| 846 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 847 | * |
| 848 | * If the intent is launched from within a managed profile with a profile |
| 849 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 850 | * this will trigger entering a new password for the parent of the profile. |
| 851 | * For all other cases it will trigger entering a new password for the user |
| 852 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 853 | * |
| 854 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 855 | */ |
| 856 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 857 | public static final String ACTION_SET_NEW_PASSWORD |
| 858 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 859 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 860 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 861 | * Activity action: have the user enter a new password for the parent profile. |
| 862 | * If the intent is launched from within a managed profile, this will trigger |
| 863 | * entering a new password for the parent of the profile. In all other cases |
| 864 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 865 | */ |
| 866 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 867 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 868 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 869 | |
| 870 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 871 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 872 | * the parent profile to access intents sent from the managed profile. |
| 873 | * That is, when an app in the managed profile calls |
| 874 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 875 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 876 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 877 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 878 | |
| 879 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 880 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 881 | * the managed profile to access intents sent from the parent profile. |
| 882 | * That is, when an app in the parent profile calls |
| 883 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 884 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 885 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 886 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 887 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 888 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 889 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 890 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 891 | */ |
| 892 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 893 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 894 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 895 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 896 | /** |
| 897 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 898 | * Already granted or denied permissions are not affected by this. |
| 899 | */ |
| 900 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 901 | |
| 902 | /** |
| 903 | * Permission policy to always grant new permission requests for runtime permissions. |
| 904 | * Already granted or denied permissions are not affected by this. |
| 905 | */ |
| 906 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 907 | |
| 908 | /** |
| 909 | * Permission policy to always deny new permission requests for runtime permissions. |
| 910 | * Already granted or denied permissions are not affected by this. |
| 911 | */ |
| 912 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 913 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 914 | /** |
| 915 | * Runtime permission state: The user can manage the permission |
| 916 | * through the UI. |
| 917 | */ |
| 918 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 919 | |
| 920 | /** |
| 921 | * Runtime permission state: The permission is granted to the app |
| 922 | * and the user cannot manage the permission through the UI. |
| 923 | */ |
| 924 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 925 | |
| 926 | /** |
| 927 | * Runtime permission state: The permission is denied to the app |
| 928 | * and the user cannot manage the permission through the UI. |
| 929 | */ |
| 930 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 931 | |
| 932 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 933 | * No management for current user in-effect. This is the default. |
| 934 | * @hide |
| 935 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 936 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 937 | public static final int STATE_USER_UNMANAGED = 0; |
| 938 | |
| 939 | /** |
| 940 | * Management partially setup, user setup needs to be completed. |
| 941 | * @hide |
| 942 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 943 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 944 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 945 | |
| 946 | /** |
| 947 | * Management partially setup, user setup completed. |
| 948 | * @hide |
| 949 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 950 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 951 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 952 | |
| 953 | /** |
| 954 | * Management setup and active on current user. |
| 955 | * @hide |
| 956 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 957 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 958 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 959 | |
| 960 | /** |
| 961 | * Management partially setup on a managed profile. |
| 962 | * @hide |
| 963 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 964 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 965 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 966 | |
| 967 | /** |
| 968 | * @hide |
| 969 | */ |
| 970 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 971 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 972 | @Retention(RetentionPolicy.SOURCE) |
| 973 | public @interface UserProvisioningState {} |
| 974 | |
| 975 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 976 | * Return true if the given administrator component is currently |
| 977 | * active (enabled) in the system. |
| 978 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 979 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 980 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | /** |
| 984 | * @see #isAdminActive(ComponentName) |
| 985 | * @hide |
| 986 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 987 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 988 | if (mService != null) { |
| 989 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 990 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 991 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 992 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | return false; |
| 996 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 997 | /** |
| 998 | * Return true if the given administrator component is currently being removed |
| 999 | * for the user. |
| 1000 | * @hide |
| 1001 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1002 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1003 | if (mService != null) { |
| 1004 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1005 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1006 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1007 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | return false; |
| 1011 | } |
| 1012 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1013 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1014 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1015 | * Return a list of all currently active device administrators' component |
| 1016 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1017 | * returned. |
| 1018 | */ |
| 1019 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1020 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * @see #getActiveAdmins() |
| 1025 | * @hide |
| 1026 | */ |
| 1027 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1028 | if (mService != null) { |
| 1029 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1030 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -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); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | return null; |
| 1036 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1037 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1038 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1039 | * Used by package administration code to determine if a package can be stopped |
| 1040 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1041 | * @hide |
| 1042 | */ |
| 1043 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1044 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Used by package administration code to determine if a package can be stopped |
| 1049 | * or uninstalled. |
| 1050 | * @hide |
| 1051 | */ |
| 1052 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1053 | if (mService != null) { |
| 1054 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1055 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1056 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1057 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | return false; |
| 1061 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1062 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1063 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1064 | * Remove a current administration component. This can only be called |
| 1065 | * by the application that owns the administration component; if you |
| 1066 | * try to remove someone else's component, a security exception will be |
| 1067 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1068 | * |
| 1069 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1070 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1071 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1072 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1073 | if (mService != null) { |
| 1074 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1075 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1076 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1077 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1081 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1082 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1083 | * 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] | 1084 | * 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] | 1085 | * but requires additional policies after an upgrade. |
| 1086 | * |
| 1087 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 1088 | * an active administrator, or an exception will be thrown. |
| 1089 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 1090 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1091 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1092 | if (mService != null) { |
| 1093 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1094 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1095 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1096 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | return false; |
| 1100 | } |
| 1101 | |
| 1102 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1103 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1104 | * |
| 1105 | * @hide |
| 1106 | */ |
| 1107 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1108 | if (mService != null) { |
| 1109 | try { |
| 1110 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1111 | } catch (RemoteException e) { |
| 1112 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1113 | } |
| 1114 | } |
| 1115 | return false; |
| 1116 | } |
| 1117 | |
| 1118 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1119 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1120 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1121 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1122 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1123 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1124 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1125 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1126 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1127 | * recognition technology. This implies technologies that can recognize the identity of |
| 1128 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1129 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1130 | */ |
| 1131 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1132 | |
| 1133 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1134 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1135 | * 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] | 1136 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1137 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1138 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1139 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1140 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1141 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1142 | * password containing at least numeric characters. Note that quality |
| 1143 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1144 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1145 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1146 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1147 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1148 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1149 | * password containing at least numeric characters with no repeating (4444) |
| 1150 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1151 | * constants are ordered so that higher values are more restrictive. |
| 1152 | */ |
| 1153 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1154 | |
| 1155 | /** |
| 1156 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1157 | * password containing at least alphabetic (or other symbol) characters. |
| 1158 | * Note that quality constants are ordered so that higher values are more |
| 1159 | * restrictive. |
| 1160 | */ |
| 1161 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1162 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1163 | /** |
| 1164 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1165 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1166 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1167 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1168 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1169 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1170 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1171 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1172 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1173 | * password containing at least a letter, a numerical digit and a special |
| 1174 | * symbol, by default. With this password quality, passwords can be |
| 1175 | * restricted to contain various sets of characters, like at least an |
| 1176 | * uppercase letter, etc. These are specified using various methods, |
| 1177 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1178 | * that quality constants are ordered so that higher values are more |
| 1179 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1180 | */ |
| 1181 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1182 | |
| 1183 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1184 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1185 | * modify password. In case this password quality is set, the password is |
| 1186 | * managed by a profile owner. The profile owner can set any password, |
| 1187 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1188 | * that quality constants are ordered so that higher values are more |
| 1189 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1190 | * the highest. |
| 1191 | * @hide |
| 1192 | */ |
| 1193 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1194 | |
| 1195 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1196 | * Called by an application that is administering the device to set the |
| 1197 | * password restrictions it is imposing. After setting this, the user |
| 1198 | * will not be able to enter a new password that is not at least as |
| 1199 | * restrictive as what has been set. Note that the current password |
| 1200 | * will remain until the user has set a new one, so the change does not |
| 1201 | * take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1202 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1203 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1204 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1205 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 1206 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1207 | * the user's preference, and any other considerations) is the one that |
| 1208 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1209 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1210 | * <p>The calling device admin must have requested |
| 1211 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1212 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1213 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1214 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1215 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1216 | * restrictions on the parent profile. |
| 1217 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1218 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1219 | * @param quality The new desired quality. One of |
| 1220 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1221 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1222 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1223 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
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 void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1226 | if (mService != null) { |
| 1227 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1228 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1229 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1230 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1234 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1235 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1236 | * Retrieve the current minimum password quality for a particular admin or all admins that set |
| 1237 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1238 | * a separate challenge are not taken into account. |
| 1239 | * |
| 1240 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1241 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1242 | * restrictions on the parent profile. |
| 1243 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1244 | * @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] | 1245 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1246 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1247 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1248 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1252 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1253 | if (mService != null) { |
| 1254 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1255 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1256 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1257 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1258 | } |
| 1259 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1260 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1261 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1262 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1263 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1264 | * Called by an application that is administering the device to set the |
| 1265 | * minimum allowed password length. After setting this, the user |
| 1266 | * will not be able to enter a new password that is not at least as |
| 1267 | * restrictive as what has been set. Note that the current password |
| 1268 | * will remain until the user has set a new one, so the change does not |
| 1269 | * take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1270 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1271 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1272 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1273 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1274 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1275 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1276 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1277 | * <p>The calling device admin must have requested |
| 1278 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1279 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1280 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1281 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1282 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1283 | * restrictions on the parent profile. |
| 1284 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1285 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1286 | * @param length The new desired minimum password length. A value of 0 |
| 1287 | * means there is no restriction. |
| 1288 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1289 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1290 | if (mService != null) { |
| 1291 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1292 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1293 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1294 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1298 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1299 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1300 | * Retrieve the current minimum password length for a particular admin or all admins that set |
| 1301 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1302 | * a separate challenge are not taken into account. |
| 1303 | * |
| 1304 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1305 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1306 | * restrictions on the parent profile. |
| 1307 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1308 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1309 | * @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] | 1310 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1311 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1312 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1313 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1317 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1318 | if (mService != null) { |
| 1319 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1320 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1321 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1322 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | return 0; |
| 1326 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1327 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1328 | /** |
| 1329 | * Called by an application that is administering the device to set the |
| 1330 | * minimum number of upper case letters required in the password. After |
| 1331 | * setting this, the user will not be able to enter a new password that is |
| 1332 | * not at least as restrictive as what has been set. Note that the current |
| 1333 | * password will remain until the user has set a new one, so the change does |
| 1334 | * not take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1335 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1336 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1337 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1338 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1339 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1340 | * <p> |
| 1341 | * The calling device admin must have requested |
| 1342 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1343 | * this method; if it has not, a security exception will be thrown. |
| 1344 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1345 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1346 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1347 | * restrictions on the parent profile. |
| 1348 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1349 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1350 | * with. |
| 1351 | * @param length The new desired minimum number of upper case letters |
| 1352 | * required in the password. A value of 0 means there is no |
| 1353 | * restriction. |
| 1354 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1355 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1356 | if (mService != null) { |
| 1357 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1358 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1359 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1360 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1366 | * Retrieve the current number of upper case letters required in the password |
| 1367 | * for a particular admin or all admins that set retrictions on this user and |
| 1368 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1369 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1370 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1371 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1372 | * and only applies when the password quality is |
| 1373 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1374 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1375 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1376 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1377 | * restrictions on the parent profile. |
| 1378 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1379 | * @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] | 1380 | * aggregate all admins. |
| 1381 | * @return The minimum number of upper case letters required in the |
| 1382 | * password. |
| 1383 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1384 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1385 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1389 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1390 | if (mService != null) { |
| 1391 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1392 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1393 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1394 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
| 1400 | /** |
| 1401 | * Called by an application that is administering the device to set the |
| 1402 | * minimum number of lower case letters required in the password. After |
| 1403 | * setting this, the user will not be able to enter a new password that is |
| 1404 | * not at least as restrictive as what has been set. Note that the current |
| 1405 | * password will remain until the user has set a new one, so the change does |
| 1406 | * not take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1407 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1408 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1409 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1410 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1411 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1412 | * <p> |
| 1413 | * The calling device admin must have requested |
| 1414 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1415 | * this method; if it has not, a security exception will be thrown. |
| 1416 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1417 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1418 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1419 | * restrictions on the parent profile. |
| 1420 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1421 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1422 | * with. |
| 1423 | * @param length The new desired minimum number of lower case letters |
| 1424 | * required in the password. A value of 0 means there is no |
| 1425 | * restriction. |
| 1426 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1427 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1428 | if (mService != null) { |
| 1429 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1430 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1431 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1432 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1438 | * Retrieve the current number of lower case letters required in the password |
| 1439 | * for a particular admin or all admins that set retrictions on this user |
| 1440 | * and its participating profiles. Restrictions on profiles that have |
| 1441 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1442 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1443 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1444 | * and only applies when the password quality is |
| 1445 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1446 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1447 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1448 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1449 | * restrictions on the parent profile. |
| 1450 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1451 | * @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] | 1452 | * aggregate all admins. |
| 1453 | * @return The minimum number of lower case letters required in the |
| 1454 | * password. |
| 1455 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1456 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1457 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1461 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1462 | if (mService != null) { |
| 1463 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1464 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1465 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1466 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
| 1472 | /** |
| 1473 | * Called by an application that is administering the device to set the |
| 1474 | * minimum number of letters required in the password. After setting this, |
| 1475 | * the user will not be able to enter a new password that is not at least as |
| 1476 | * restrictive as what has been set. Note that the current password will |
| 1477 | * remain until the user has set a new one, so the change does not take |
| 1478 | * place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1479 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1480 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1481 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1482 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1483 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1484 | * <p> |
| 1485 | * The calling device admin must have requested |
| 1486 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1487 | * this method; if it has not, a security exception will be thrown. |
| 1488 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1489 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1490 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1491 | * restrictions on the parent profile. |
| 1492 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1493 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1494 | * with. |
| 1495 | * @param length The new desired minimum number of letters required in the |
| 1496 | * password. A value of 0 means there is no restriction. |
| 1497 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1498 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1499 | if (mService != null) { |
| 1500 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1501 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1502 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1503 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1509 | * Retrieve the current number of letters required in the password |
| 1510 | * for a particular admin or all admins that set retrictions on this user |
| 1511 | * and its participating profiles. Restrictions on profiles that have |
| 1512 | * a separate challenge are not taken into account. |
| 1513 | * This is the same value as set by |
| 1514 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 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 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1518 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1519 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1520 | * restrictions on the parent profile. |
| 1521 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1522 | * @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] | 1523 | * aggregate all admins. |
| 1524 | * @return The minimum number of letters required in the password. |
| 1525 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1526 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1527 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1531 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1532 | if (mService != null) { |
| 1533 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1534 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1535 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1536 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | return 0; |
| 1540 | } |
| 1541 | |
| 1542 | /** |
| 1543 | * Called by an application that is administering the device to set the |
| 1544 | * minimum number of numerical digits required in the password. After |
| 1545 | * setting this, the user will not be able to enter a new password that is |
| 1546 | * not at least as restrictive as what has been set. Note that the current |
| 1547 | * password will remain until the user has set a new one, so the change does |
| 1548 | * not take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1549 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1550 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1551 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1552 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1553 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1554 | * <p> |
| 1555 | * The calling device admin must have requested |
| 1556 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1557 | * this method; if it has not, a security exception will be thrown. |
| 1558 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1559 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1560 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1561 | * restrictions on the parent profile. |
| 1562 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1563 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1564 | * with. |
| 1565 | * @param length The new desired minimum number of numerical digits required |
| 1566 | * in the password. A value of 0 means there is no restriction. |
| 1567 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1568 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1569 | if (mService != null) { |
| 1570 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1571 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1572 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1573 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | /** |
| 1579 | * Retrieve the current number of numerical digits required in the password |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1580 | * for a particular admin or all admins that set retrictions on this user |
| 1581 | * and its participating profiles. Restrictions on profiles that have |
| 1582 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1583 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1584 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1585 | * and only applies when the password quality is |
| 1586 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1587 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1588 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1589 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1590 | * restrictions on the parent profile. |
| 1591 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1592 | * @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] | 1593 | * aggregate all admins. |
| 1594 | * @return The minimum number of numerical digits required in the password. |
| 1595 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1596 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1597 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1601 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1602 | if (mService != null) { |
| 1603 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1604 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1605 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1606 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
| 1612 | /** |
| 1613 | * Called by an application that is administering the device to set the |
| 1614 | * minimum number of symbols required in the password. After setting this, |
| 1615 | * the user will not be able to enter a new password that is not at least as |
| 1616 | * restrictive as what has been set. Note that the current password will |
| 1617 | * remain until the user has set a new one, so the change does not take |
| 1618 | * place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1619 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1620 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1621 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1622 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1623 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1624 | * <p> |
| 1625 | * The calling device admin must have requested |
| 1626 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1627 | * this method; if it has not, a security exception will be thrown. |
| 1628 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1629 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1630 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1631 | * restrictions on the parent profile. |
| 1632 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1633 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1634 | * with. |
| 1635 | * @param length The new desired minimum number of symbols required in the |
| 1636 | * password. A value of 0 means there is no restriction. |
| 1637 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1638 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1639 | if (mService != null) { |
| 1640 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1641 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1642 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1643 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1649 | * Retrieve the current number of symbols required in the password |
| 1650 | * for a particular admin or all admins that set retrictions on this user |
| 1651 | * and its participating profiles. Restrictions on profiles that have |
| 1652 | * a separate challenge are not taken into account. This is the same value as |
| 1653 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1654 | * and only applies when the password quality is |
| 1655 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1656 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1657 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1658 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1659 | * restrictions on the parent profile. |
| 1660 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1661 | * @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] | 1662 | * aggregate all admins. |
| 1663 | * @return The minimum number of symbols required in the password. |
| 1664 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1665 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1666 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1670 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1671 | if (mService != null) { |
| 1672 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1673 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [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); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | return 0; |
| 1679 | } |
| 1680 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1681 | /** |
| 1682 | * Called by an application that is administering the device to set the |
| 1683 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1684 | * required in the password. After setting this, the user will not be able |
| 1685 | * to enter a new password that is not at least as restrictive as what has |
| 1686 | * been set. Note that the current password will remain until the user has |
| 1687 | * set a new one, so the change does not take place immediately. To prompt |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1688 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1689 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1690 | * setting this value. This constraint is only imposed if the administrator |
| 1691 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1692 | * {@link #setPasswordQuality}. The default value is 0. |
| 1693 | * <p> |
| 1694 | * The calling device admin must have requested |
| 1695 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1696 | * this method; if it has not, a security exception will be thrown. |
| 1697 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1698 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1699 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1700 | * restrictions on the parent profile. |
| 1701 | * |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1702 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1703 | * with. |
| 1704 | * @param length The new desired minimum number of letters required in the |
| 1705 | * password. A value of 0 means there is no restriction. |
| 1706 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1707 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1708 | if (mService != null) { |
| 1709 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1710 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1711 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1712 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1713 | } |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1718 | * Retrieve the current number of non-letter characters required in the password |
| 1719 | * for a particular admin or all admins that set retrictions on this user |
| 1720 | * and its participating profiles. Restrictions on profiles that have |
| 1721 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1722 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1723 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1724 | * and only applies when the password quality is |
| 1725 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1726 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1727 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1728 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1729 | * restrictions on the parent profile. |
| 1730 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1731 | * @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] | 1732 | * aggregate all admins. |
| 1733 | * @return The minimum number of letters required in the password. |
| 1734 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1735 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1736 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1740 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1741 | if (mService != null) { |
| 1742 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1743 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1744 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1745 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1751 | /** |
| 1752 | * Called by an application that is administering the device to set the length |
| 1753 | * of the password history. After setting this, the user will not be able to |
| 1754 | * enter a new password that is the same as any password in the history. Note |
| 1755 | * that the current password will remain until the user has set a new one, so |
| 1756 | * the change does not take place immediately. To prompt the user for a new |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1757 | * password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1758 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1759 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1760 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1761 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1762 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1763 | * |
| 1764 | * <p> |
| 1765 | * The calling device admin must have requested |
| 1766 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1767 | * method; if it has not, a security exception will be thrown. |
| 1768 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1769 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1770 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1771 | * restrictions on the parent profile. |
| 1772 | * |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1773 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1774 | * with. |
| 1775 | * @param length The new desired length of password history. A value of 0 |
| 1776 | * means there is no restriction. |
| 1777 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1778 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1779 | if (mService != null) { |
| 1780 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1781 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1782 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1783 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1789 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1790 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1791 | * the device password (for all admins). |
| 1792 | * |
| 1793 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1794 | * For example, to have the password expire 5 days from now, timeout would be |
| 1795 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1796 | * |
| 1797 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1798 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1799 | * <p>The calling device admin must have requested |
| 1800 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1801 | * method; if it has not, a security exception will be thrown. |
| 1802 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1803 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1804 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1805 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1806 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1807 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1808 | * restrictions on the parent profile. |
| 1809 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1810 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1811 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1812 | * means there is no restriction (unlimited). |
| 1813 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1814 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1815 | if (mService != null) { |
| 1816 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1817 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1818 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1819 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1825 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1826 | * recurring expiration timeout provided in the call to |
| 1827 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1828 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 1829 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 1830 | * |
| 1831 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1832 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1833 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1834 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1835 | * @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] | 1836 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1837 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1838 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1839 | if (mService != null) { |
| 1840 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1841 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1842 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1843 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
| 1849 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1850 | * Get the current password expiration time for a particular admin or all admins that set |
| 1851 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1852 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 1853 | * of all expiration times is returned - which will be the minimum of all of them. |
| 1854 | * |
| 1855 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1856 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1857 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1858 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1859 | * @param admin The name of the admin component to check, or {@code null} to aggregate all admins. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1860 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1861 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1862 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1863 | if (mService != null) { |
| 1864 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1865 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1866 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1867 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | return 0; |
| 1871 | } |
| 1872 | |
| 1873 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1874 | * Retrieve the current password history length for a particular admin or all admins that |
| 1875 | * set retrictions on this user and its participating profiles. Restrictions on profiles that |
| 1876 | * have a separate challenge are not taken into account. |
| 1877 | * |
| 1878 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1879 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1880 | * restrictions on the parent profile. |
| 1881 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1882 | * @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] | 1883 | * all admins. |
| 1884 | * @return The length of the password history |
| 1885 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1886 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1887 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1891 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1892 | if (mService != null) { |
| 1893 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1894 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1895 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1896 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1897 | } |
| 1898 | } |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1902 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1903 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1904 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1905 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1906 | * @return Returns the maximum length that the user can enter. |
| 1907 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1908 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1909 | // Kind-of arbitrary. |
| 1910 | return 16; |
| 1911 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1912 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1913 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1914 | * Determine whether the current password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1915 | * to meet the policy requirements (e.g. quality, minimum length) that have been |
| 1916 | * requested by the admins of this user and its participating profiles. |
| 1917 | * Restrictions on profiles that have a separate challenge are not taken into account. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1918 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1919 | * <p>The calling device admin must have requested |
| 1920 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1921 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1922 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1923 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1924 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to determine |
| 1925 | * if the password set on the parent profile is sufficient. |
| 1926 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1927 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1928 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1929 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1930 | if (mService != null) { |
| 1931 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1932 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1933 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1934 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1935 | } |
| 1936 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1937 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1938 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1939 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1940 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1941 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1942 | * to meet the policy requirements (e.g. quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1943 | * requested by the admins of the parent user and its profiles. |
| 1944 | * |
| 1945 | * @param userHandle the userId of the profile to check the password for. |
| 1946 | * @return Returns true if the password would meet the current requirements, else false. |
| 1947 | * @hide |
| 1948 | */ |
| 1949 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 1950 | if (mService != null) { |
| 1951 | try { |
| 1952 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 1953 | } catch (RemoteException e) { |
| 1954 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1955 | } |
| 1956 | } |
| 1957 | return false; |
| 1958 | } |
| 1959 | |
| 1960 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1961 | * Retrieve the number of times the user has failed at entering a |
| 1962 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1963 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1964 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1965 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1966 | * the number of failed password attemts for the parent user. |
| 1967 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1968 | * <p>The calling device admin must have requested |
| 1969 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1970 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1971 | */ |
| 1972 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 1973 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * Retrieve the number of times the given user has failed at entering a |
| 1978 | * password since that last successful password entry. |
| 1979 | * |
| 1980 | * <p>The calling device admin must have requested |
| 1981 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 1982 | * not and it is not the system uid, a security exception will be thrown. |
| 1983 | * |
| 1984 | * @hide |
| 1985 | */ |
| 1986 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1987 | if (mService != null) { |
| 1988 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 1989 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1990 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1991 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | return -1; |
| 1995 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1996 | |
| 1997 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1998 | * 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] | 1999 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2000 | * @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] | 2001 | * @hide |
| 2002 | */ |
| 2003 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2004 | if (mService != null) { |
| 2005 | try { |
| 2006 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2007 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2008 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2009 | } |
| 2010 | } |
| 2011 | return false; |
| 2012 | } |
| 2013 | |
| 2014 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2015 | * Setting this to a value greater than zero enables a built-in policy |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2016 | * that will perform a device or profile wipe after too many incorrect |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2017 | * device-unlock passwords have been entered. This built-in policy combines |
| 2018 | * watching for failed passwords and wiping the device, and requires |
| 2019 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2020 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2021 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2022 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 2023 | * application only, erasing or revoking credentials, or reporting the |
| 2024 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2025 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2026 | * instead. Do not use this API, because if the maximum count is reached, |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2027 | * the device or profile will be wiped immediately, and your callback will not be invoked. |
| 2028 | * |
| 2029 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2030 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 2031 | * a value on the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2032 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2033 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2034 | * @param num The number of failed password attempts at which point the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2035 | * device or profile will be wiped. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2036 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2037 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2038 | if (mService != null) { |
| 2039 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2040 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2041 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2042 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2046 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2047 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2048 | * Retrieve the current maximum number of login attempts that are allowed before the device |
| 2049 | * or profile is wiped, for a particular admin or all admins that set retrictions on this user |
| 2050 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2051 | * not taken into account. |
| 2052 | * |
| 2053 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2054 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2055 | * the value for the parent profile. |
| 2056 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2057 | * @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] | 2058 | * all admins. |
| 2059 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2060 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2061 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2065 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2066 | if (mService != null) { |
| 2067 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2068 | return mService.getMaximumFailedPasswordsForWipe( |
| 2069 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2070 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2071 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | return 0; |
| 2075 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2076 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2077 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2078 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2079 | * for the given user. So for primary user, it might return the primary or |
| 2080 | * a managed profile. For a secondary user, it would be the same as the |
| 2081 | * user passed in. |
| 2082 | * @hide Used only by Keyguard |
| 2083 | */ |
| 2084 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2085 | if (mService != null) { |
| 2086 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2087 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2088 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2089 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2090 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | return UserHandle.USER_NULL; |
| 2094 | } |
| 2095 | |
| 2096 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2097 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2098 | * the password again until the user has entered it. |
| 2099 | */ |
| 2100 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2101 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2102 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2103 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2104 | * If the flag is set, the device can be booted without asking for user password. |
| 2105 | * The absence of this flag does not change the current boot requirements. This flag |
| 2106 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2107 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2108 | * device to factory defaults. |
| 2109 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2110 | 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] | 2111 | |
| 2112 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2113 | * Force a new device unlock password (the password needed to access the |
| 2114 | * entire device, not for individual accounts) on the user. This takes |
| 2115 | * effect immediately. |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2116 | * |
| 2117 | * <p>Calling this from a managed profile that shares the password with the owner profile |
| 2118 | * will throw a security exception. |
| 2119 | * |
| 2120 | * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
| 2121 | * device admins that are not device owner and not profile owner. |
| 2122 | * The password can now only be changed if there is currently no password set. Device owner |
| 2123 | * and profile owner can still do this.</em> |
| 2124 | * |
| 2125 | * <p>The given password must be sufficient for the |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2126 | * current password quality and length constraints as returned by |
| 2127 | * {@link #getPasswordQuality(ComponentName)} and |
| 2128 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 2129 | * these constraints, then it will be rejected and false returned. Note |
| 2130 | * that the password may be a stronger quality (containing alphanumeric |
| 2131 | * characters when the requested quality is only numeric), in which case |
| 2132 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2133 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2134 | * <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] | 2135 | * pattern or password if the current password constraints allow it. <em>Note: This will not |
| 2136 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 2137 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 2138 | * empty, except by device owner or profile owner.</em> |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2139 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2140 | * <p>The calling device admin must have requested |
| 2141 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 2142 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2143 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2144 | * @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] | 2145 | * @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] | 2146 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2147 | * @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] | 2148 | * 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] | 2149 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2150 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2151 | if (mParentInstance) { |
| 2152 | throw new SecurityException("Reset password does not work across profiles."); |
| 2153 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2154 | if (mService != null) { |
| 2155 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2156 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2157 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2158 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2159 | } |
| 2160 | } |
| 2161 | return false; |
| 2162 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2163 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2164 | /** |
| 2165 | * Called by an application that is administering the device to set the |
| 2166 | * maximum time for user activity until the device will lock. This limits |
| 2167 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2168 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2169 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 2170 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2171 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2172 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2173 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2174 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 2175 | * restrictions on the parent profile. |
| 2176 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2177 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2178 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 2179 | * A value of 0 means there is no restriction. |
| 2180 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2181 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2182 | if (mService != null) { |
| 2183 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2184 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2185 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2186 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2187 | } |
| 2188 | } |
| 2189 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2190 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2191 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2192 | * Retrieve the current maximum time to unlock for a particular admin or all admins that set |
| 2193 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 2194 | * a separate challenge are not taken into account. |
| 2195 | * |
| 2196 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2197 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2198 | * restrictions on the parent profile. |
| 2199 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2200 | * @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] | 2201 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2202 | * @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] | 2203 | * 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] | 2204 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2205 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2206 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2210 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2211 | if (mService != null) { |
| 2212 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2213 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2214 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2215 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2216 | } |
| 2217 | } |
| 2218 | return 0; |
| 2219 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2220 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2221 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2222 | * Make the device lock immediately, as if the lock screen timeout has |
| 2223 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2224 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2225 | * <p>The calling device admin must have requested |
| 2226 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 2227 | * this method; if it has not, a security exception will be thrown. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2228 | * |
| 2229 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2230 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to lock |
| 2231 | * the parent profile. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2232 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2233 | public void lockNow() { |
| 2234 | if (mService != null) { |
| 2235 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2236 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2237 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2238 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2239 | } |
| 2240 | } |
| 2241 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2242 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2243 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2244 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2245 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2246 | */ |
| 2247 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2248 | |
| 2249 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2250 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2251 | * data. |
| 2252 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2253 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2254 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2255 | */ |
| 2256 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2257 | |
| 2258 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 2259 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 2260 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2261 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2262 | * <p>The calling device admin must have requested |
| 2263 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 2264 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2265 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2266 | * @param flags Bit mask of additional options: currently supported flags |
| 2267 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 2268 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2269 | */ |
| 2270 | public void wipeData(int flags) { |
| 2271 | if (mService != null) { |
| 2272 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2273 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2274 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2275 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2276 | } |
| 2277 | } |
| 2278 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2279 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2280 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2281 | * Called by an application that is administering the device to set the |
| 2282 | * global proxy and exclusion list. |
| 2283 | * <p> |
| 2284 | * The calling device admin must have requested |
| 2285 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2286 | * this method; if it has not, a security exception will be thrown. |
| 2287 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2288 | * 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] | 2289 | * 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] | 2290 | * be returned. |
| 2291 | * The method can be called repeatedly by the device admin alrady setting the |
| 2292 | * proxy to update the proxy and exclusion list. |
| 2293 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2294 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2295 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2296 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2297 | * @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] | 2298 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2299 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2300 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2301 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2302 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2303 | List<String> exclusionList ) { |
| 2304 | if (proxySpec == null) { |
| 2305 | throw new NullPointerException(); |
| 2306 | } |
| 2307 | if (mService != null) { |
| 2308 | try { |
| 2309 | String hostSpec; |
| 2310 | String exclSpec; |
| 2311 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2312 | hostSpec = null; |
| 2313 | exclSpec = null; |
| 2314 | } else { |
| 2315 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2316 | throw new IllegalArgumentException(); |
| 2317 | } |
| 2318 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2319 | String hostName = sa.getHostName(); |
| 2320 | int port = sa.getPort(); |
| 2321 | StringBuilder hostBuilder = new StringBuilder(); |
| 2322 | hostSpec = hostBuilder.append(hostName) |
| 2323 | .append(":").append(Integer.toString(port)).toString(); |
| 2324 | if (exclusionList == null) { |
| 2325 | exclSpec = ""; |
| 2326 | } else { |
| 2327 | StringBuilder listBuilder = new StringBuilder(); |
| 2328 | boolean firstDomain = true; |
| 2329 | for (String exclDomain : exclusionList) { |
| 2330 | if (!firstDomain) { |
| 2331 | listBuilder = listBuilder.append(","); |
| 2332 | } else { |
| 2333 | firstDomain = false; |
| 2334 | } |
| 2335 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2336 | } |
| 2337 | exclSpec = listBuilder.toString(); |
| 2338 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2339 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2340 | != android.net.Proxy.PROXY_VALID) |
| 2341 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2342 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2343 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2344 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2345 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | return null; |
| 2349 | } |
| 2350 | |
| 2351 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2352 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 2353 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 2354 | * doing something unusual like general internal filtering this may be useful. On |
| 2355 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 2356 | * |
| 2357 | * <p>This method requires the caller to be the device owner. |
| 2358 | * |
| 2359 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 2360 | * @see ProxyInfo |
| 2361 | * |
| 2362 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2363 | * with. |
| 2364 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 2365 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 2366 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2367 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2368 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2369 | if (mService != null) { |
| 2370 | try { |
| 2371 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2372 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2373 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2379 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2380 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2381 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2382 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2383 | */ |
| 2384 | public ComponentName getGlobalProxyAdmin() { |
| 2385 | if (mService != null) { |
| 2386 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2387 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2388 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2389 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | return null; |
| 2393 | } |
| 2394 | |
| 2395 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2396 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2397 | * indicating that encryption is not supported. |
| 2398 | */ |
| 2399 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2400 | |
| 2401 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2402 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2403 | * indicating that encryption is supported, but is not currently active. |
| 2404 | */ |
| 2405 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2406 | |
| 2407 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2408 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2409 | * indicating that encryption is not currently active, but is currently |
| 2410 | * being activated. This is only reported by devices that support |
| 2411 | * encryption of data and only when the storage is currently |
| 2412 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2413 | * to become encrypted will never return this value. |
| 2414 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2415 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2416 | |
| 2417 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2418 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2419 | * indicating that encryption is active. |
| 2420 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2421 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2422 | |
| 2423 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2424 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2425 | * indicating that encryption is active, but an encryption key has not |
| 2426 | * been set by the user. |
| 2427 | */ |
| 2428 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2429 | |
| 2430 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2431 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2432 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2433 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2434 | * to check encryption status. However, on some devices this activity may never return, as |
| 2435 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2436 | */ |
| 2437 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2438 | public static final String ACTION_START_ENCRYPTION |
| 2439 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2440 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2441 | * Widgets are enabled in keyguard |
| 2442 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2443 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2444 | |
| 2445 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2446 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2447 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2448 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2449 | |
| 2450 | /** |
| 2451 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2452 | */ |
| 2453 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2454 | |
| 2455 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2456 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2457 | */ |
| 2458 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2459 | |
| 2460 | /** |
| 2461 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2462 | */ |
| 2463 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2464 | |
| 2465 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2466 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2467 | * (e.g. PIN/Pattern/Password). |
| 2468 | */ |
| 2469 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2470 | |
| 2471 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2472 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2473 | */ |
| 2474 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2475 | |
| 2476 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2477 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2478 | */ |
| 2479 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2480 | |
| 2481 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2482 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2483 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2484 | * |
| 2485 | * <p>When multiple device administrators attempt to control device |
| 2486 | * encryption, the most secure, supported setting will always be |
| 2487 | * used. If any device administrator requests device encryption, |
| 2488 | * it will be enabled; Conversely, if a device administrator |
| 2489 | * attempts to disable device encryption while another |
| 2490 | * device administrator has enabled it, the call to disable will |
| 2491 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2492 | * |
| 2493 | * <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] | 2494 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2495 | * or control the encryption of any other storage areas. |
| 2496 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2497 | * {@code true}, then the directory returned by |
| 2498 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2499 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2500 | * |
| 2501 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2502 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2503 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2504 | * also require (and check for) a pattern, PIN, or password. |
| 2505 | * |
| 2506 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2507 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2508 | * @return the new request status (for all active admins) - will be one of |
| 2509 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2510 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2511 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2512 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2513 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2514 | if (mService != null) { |
| 2515 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2516 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2517 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2518 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2522 | } |
| 2523 | |
| 2524 | /** |
| 2525 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2526 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2527 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2528 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2529 | * this will return the requested encryption setting as an aggregate of all active |
| 2530 | * administrators. |
| 2531 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2532 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2533 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2534 | if (mService != null) { |
| 2535 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2536 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2537 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2538 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2539 | } |
| 2540 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2541 | return false; |
| 2542 | } |
| 2543 | |
| 2544 | /** |
| 2545 | * Called by an application that is administering the device to |
| 2546 | * determine the current encryption status of the device. |
| 2547 | * |
| 2548 | * Depending on the returned status code, the caller may proceed in different |
| 2549 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2550 | * storage system does not support encryption. If the |
| 2551 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2552 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2553 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2554 | * storage system has enabled encryption but no password is set so further action |
| 2555 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2556 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2557 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2558 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2559 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2560 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2561 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2562 | */ |
| 2563 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2564 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | /** @hide per-user version */ |
| 2568 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2569 | if (mService != null) { |
| 2570 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2571 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2572 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2573 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2574 | } |
| 2575 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2576 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2577 | } |
| 2578 | |
| 2579 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2580 | * Installs the given certificate as a user CA. |
| 2581 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2582 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2583 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2584 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2585 | * |
| 2586 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2587 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2588 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2589 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2590 | if (mService != null) { |
| 2591 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2592 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2593 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2594 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | return false; |
| 2598 | } |
| 2599 | |
| 2600 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2601 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2602 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2603 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2604 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2605 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2606 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2607 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2608 | if (mService != null) { |
| 2609 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2610 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2611 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2612 | } catch (CertificateException e) { |
| 2613 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2614 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2615 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2621 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2622 | * If a user has installed any certificates by other means than device policy these will be |
| 2623 | * included too. |
| 2624 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2625 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2626 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2627 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2628 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2629 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2630 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2631 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2632 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2633 | mService.enforceCanManageCaCerts(admin); |
| 2634 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2635 | for (String alias : certStore.userAliases()) { |
| 2636 | try { |
| 2637 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2638 | } catch (CertificateException ce) { |
| 2639 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2640 | } |
| 2641 | } |
| 2642 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2643 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2644 | } |
| 2645 | } |
| 2646 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2650 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2651 | * means other than device policy will also be removed, except for system CA certificates. |
| 2652 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2653 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2654 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2655 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2656 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2657 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2658 | try { |
| 2659 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2660 | .toArray(new String[0])); |
| 2661 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2662 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2663 | } |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | /** |
| 2668 | * Returns whether this certificate is installed as a trusted CA. |
| 2669 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2670 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2671 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2672 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2673 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2674 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2675 | if (mService != null) { |
| 2676 | try { |
| 2677 | mService.enforceCanManageCaCerts(admin); |
| 2678 | return getCaCertAlias(certBuffer) != null; |
| 2679 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2680 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2681 | } catch (CertificateException ce) { |
| 2682 | Log.w(TAG, "Could not parse certificate", ce); |
| 2683 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2684 | } |
| 2685 | return false; |
| 2686 | } |
| 2687 | |
| 2688 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2689 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2690 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2691 | * the certificate and use the private key, given direct user approval. |
| 2692 | * |
| 2693 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 2694 | * direct user approval. This is for security - should a certificate installer become |
| 2695 | * compromised, certificates it had already installed will be protected. |
| 2696 | * |
| 2697 | * <p>If the installer must have access to the credentials, call |
| 2698 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate, String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2699 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2700 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2701 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2702 | * @param privKey The private key to install. |
| 2703 | * @param cert The certificate to install. |
| 2704 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2705 | * with that alias already exists, it will be overwritten. |
| 2706 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2707 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2708 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2709 | @NonNull Certificate cert, @NonNull String alias) { |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2710 | return installKeyPair(admin, privKey, cert, alias, false); |
| 2711 | } |
| 2712 | |
| 2713 | /** |
| 2714 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2715 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2716 | * the certificate and use the private key, given direct user approval. |
| 2717 | * |
| 2718 | * <p>The caller of this API may grant itself access to the credential immediately, without user |
| 2719 | * approval. It is a best practice not to request this unless strictly necessary since it opens |
| 2720 | * up additional security vulnerabilities. |
| 2721 | * |
| 2722 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2723 | * {@code null} if calling from a delegated certificate installer. |
| 2724 | * @param privKey The private key to install. |
| 2725 | * @param cert The certificate to install. |
| 2726 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2727 | * with that alias already exists, it will be overwritten. |
| 2728 | * @param requestAccess {@code true} to request that the calling app be granted access to the |
| 2729 | * credentials immediately. Otherwise, access to the credentials will be gated by user approval. |
| 2730 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2731 | */ |
| 2732 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2733 | @NonNull Certificate cert, @NonNull String alias, boolean requestAccess) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2734 | try { |
| 2735 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2736 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2737 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2738 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2739 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2740 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2741 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2742 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2743 | } catch (CertificateException | IOException e) { |
| 2744 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2745 | } |
| 2746 | return false; |
| 2747 | } |
| 2748 | |
| 2749 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2750 | * Called by a device or profile owner, or delegated certificate installer, to remove all user |
| 2751 | * credentials installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2752 | * |
| 2753 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2754 | * {@code null} if calling from a delegated certificate installer. |
| 2755 | * @param alias The private key alias under which the certificate is installed. |
| 2756 | * @return {@code true} if the keys were both removed, {@code false} otherwise. |
| 2757 | */ |
| 2758 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2759 | try { |
| 2760 | return mService.removeKeyPair(admin, alias); |
| 2761 | } catch (RemoteException e) { |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2762 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2763 | } |
| 2764 | return false; |
| 2765 | } |
| 2766 | |
| 2767 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2768 | * @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] | 2769 | * doesn't exist. |
| 2770 | */ |
| 2771 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2772 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2773 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2774 | new ByteArrayInputStream(certBuffer)); |
| 2775 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2776 | } |
| 2777 | |
| 2778 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2779 | * 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] | 2780 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2781 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2782 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2783 | * <p> |
| 2784 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2785 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2786 | * installer. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 2787 | *<p> |
| 2788 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 2789 | * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the |
| 2790 | * supplied certificate installer package must be installed when calling this API, |
| 2791 | * otherwise an {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2792 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2793 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2794 | * @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] | 2795 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2796 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2797 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2798 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2799 | if (mService != null) { |
| 2800 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2801 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2802 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2803 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | /** |
| 2809 | * 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] | 2810 | * user. null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2811 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2812 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2813 | * @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] | 2814 | * if none is set. |
| 2815 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2816 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2817 | if (mService != null) { |
| 2818 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2819 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2820 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2821 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | return null; |
| 2825 | } |
| 2826 | |
| 2827 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2828 | * Called by a device or profile owner to configure an always-on VPN connection through a |
| 2829 | * specific application for the current user. |
| 2830 | * This connection is automatically granted and persisted after a reboot. |
| 2831 | * |
| 2832 | * <p>The designated package should declare a {@link android.net.VpnService} in its |
| 2833 | * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, |
| 2834 | * otherwise the call will fail. |
| 2835 | * |
| 2836 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} |
| 2837 | * to remove an existing always-on VPN configuration. |
| 2838 | * |
| 2839 | * @return {@code true} if the package is set as always-on VPN controller; |
| 2840 | * {@code false} otherwise. |
| 2841 | */ |
| 2842 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2843 | @Nullable String vpnPackage) { |
| 2844 | if (mService != null) { |
| 2845 | try { |
| 2846 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2847 | } catch (RemoteException e) { |
| 2848 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2849 | } |
| 2850 | } |
| 2851 | return false; |
| 2852 | } |
| 2853 | |
| 2854 | /** |
| 2855 | * Called by a device or profile owner to read the name of the package administering an |
| 2856 | * always-on VPN connection for the current user. |
| 2857 | * If there is no such package, or the always-on VPN is provided by the system instead |
| 2858 | * of by an application, {@code null} will be returned. |
| 2859 | * |
| 2860 | * @return Package name of VPN controller responsible for always-on VPN, |
| 2861 | * or {@code null} if none is set. |
| 2862 | */ |
| 2863 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2864 | if (mService != null) { |
| 2865 | try { |
| 2866 | return mService.getAlwaysOnVpnPackage(admin); |
| 2867 | } catch (RemoteException e) { |
| 2868 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2869 | } |
| 2870 | } |
| 2871 | return null; |
| 2872 | } |
| 2873 | |
| 2874 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2875 | * 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] | 2876 | * on the device, for this user. After setting this, no applications running as this user |
| 2877 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2878 | * |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 2879 | * <p>If the caller is device owner, then the restriction will be applied to all users. |
| 2880 | * |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2881 | * <p>The calling device admin must have requested |
| 2882 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2883 | * this method; if it has not, a security exception will be thrown. |
| 2884 | * |
| 2885 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2886 | * @param disabled Whether or not the camera should be disabled. |
| 2887 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2888 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2889 | if (mService != null) { |
| 2890 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2891 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2892 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2893 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2894 | } |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2899 | * 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] | 2900 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2901 | * @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] | 2902 | * have disabled the camera |
| 2903 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2904 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2905 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2909 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2910 | if (mService != null) { |
| 2911 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2912 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2913 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2914 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | return false; |
| 2918 | } |
| 2919 | |
| 2920 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2921 | * Called by a device owner to request a bugreport. |
| 2922 | * |
| 2923 | * <p>There must be only one user on the device, managed by the device owner. |
| 2924 | * Otherwise a security exception will be thrown. |
| 2925 | * |
| 2926 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2927 | * @return {@code true} if the bugreport collection started successfully, or {@code false} |
| 2928 | * if it wasn't triggered because a previous bugreport operation is still active |
| 2929 | * (either the bugreport is still running or waiting for the user to share or decline) |
| 2930 | */ |
| 2931 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 2932 | if (mService != null) { |
| 2933 | try { |
| 2934 | return mService.requestBugreport(admin); |
| 2935 | } catch (RemoteException e) { |
| 2936 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2937 | } |
| 2938 | } |
| 2939 | return false; |
| 2940 | } |
| 2941 | |
| 2942 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2943 | * Determine whether or not creating a guest user has been disabled for the device |
| 2944 | * |
| 2945 | * @hide |
| 2946 | */ |
| 2947 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 2948 | // Currently guest users can always be created if multi-user is enabled |
| 2949 | // TODO introduce a policy for guest user creation |
| 2950 | return false; |
| 2951 | } |
| 2952 | |
| 2953 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2954 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2955 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2956 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2957 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2958 | * |
| 2959 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2960 | * security exception will be thrown. |
| 2961 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2962 | * <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] | 2963 | * blocks assist requests for all activities of the relevant user. |
| 2964 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2965 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2966 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2967 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2968 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2969 | if (mService != null) { |
| 2970 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2971 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [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); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | } |
| 2977 | |
| 2978 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2979 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2980 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2981 | * @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] | 2982 | * have disabled screen capture. |
| 2983 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2984 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2985 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2989 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2990 | if (mService != null) { |
| 2991 | try { |
| 2992 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2993 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2994 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | return false; |
| 2998 | } |
| 2999 | |
| 3000 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3001 | * Called by a device owner to set whether auto time is required. If auto time is |
| 3002 | * required the user cannot set the date and time, but has to use network date and time. |
| 3003 | * |
| 3004 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 3005 | * |
| 3006 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 3007 | * be thrown. |
| 3008 | * |
| 3009 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3010 | * @param required Whether auto time is set required or not. |
| 3011 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3012 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3013 | if (mService != null) { |
| 3014 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3015 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3016 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3017 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3018 | } |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | /** |
| 3023 | * @return true if auto time is required. |
| 3024 | */ |
| 3025 | public boolean getAutoTimeRequired() { |
| 3026 | if (mService != null) { |
| 3027 | try { |
| 3028 | return mService.getAutoTimeRequired(); |
| 3029 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3030 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3031 | } |
| 3032 | } |
| 3033 | return false; |
| 3034 | } |
| 3035 | |
| 3036 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3037 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
| 3038 | * |
| 3039 | * <p>The system user is exempt from this policy - it is never ephemeral. |
| 3040 | * |
| 3041 | * <p>The calling device admin must be the device owner. If it is not, a security exception will |
| 3042 | * be thrown. |
| 3043 | * |
| 3044 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3045 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
| 3046 | * subsequently created users will be ephemeral. |
| 3047 | * @hide |
| 3048 | */ |
| 3049 | public void setForceEphemeralUsers( |
| 3050 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 3051 | if (mService != null) { |
| 3052 | try { |
| 3053 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3054 | } catch (RemoteException e) { |
| 3055 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3056 | } |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | /** |
| 3061 | * @return true if all users are created ephemeral. |
| 3062 | * @hide |
| 3063 | */ |
| 3064 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 3065 | if (mService != null) { |
| 3066 | try { |
| 3067 | return mService.getForceEphemeralUsers(admin); |
| 3068 | } catch (RemoteException e) { |
| 3069 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3070 | } |
| 3071 | } |
| 3072 | return false; |
| 3073 | } |
| 3074 | |
| 3075 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3076 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3077 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3078 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3079 | * |
| 3080 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3081 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3082 | * this method; if it has not, a security exception will be thrown. |
| 3083 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3084 | * <p>Calling this from a managed profile before version |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3085 | * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. From version |
| 3086 | * {@link android.os.Build.VERSION_CODES#M} the profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3087 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3088 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there |
| 3089 | * is no separate challenge set on the managed profile. |
| 3090 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
| 3091 | * there is one, or the parent user otherwise. |
| 3092 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications |
| 3093 | * generated by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3094 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3095 | * |
| 3096 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3097 | * set on the {@link DevicePolicyManager} instance returned by |
| 3098 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the |
| 3099 | * parent profile. |
| 3100 | * |
| 3101 | * <p>Requests to disable other features on a managed profile will be ignored. |
| 3102 | * |
| 3103 | * <p>The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3104 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3105 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3106 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3107 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 3108 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3109 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3110 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 3111 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3112 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3113 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3114 | if (mService != null) { |
| 3115 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3116 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3117 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3118 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3119 | } |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3124 | * Determine whether or not features have been disabled in keyguard either by the calling |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3125 | * admin, if specified, or all admins that set retrictions on this user and its participating |
| 3126 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3127 | * |
| 3128 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3129 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3130 | * restrictions on the parent profile. |
| 3131 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3132 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3133 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3134 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3135 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3136 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3137 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3138 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3142 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3143 | if (mService != null) { |
| 3144 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3145 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3146 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3147 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3148 | } |
| 3149 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3150 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3154 | * @hide |
| 3155 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3156 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3157 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3158 | if (mService != null) { |
| 3159 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3160 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3161 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3162 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3163 | } |
| 3164 | } |
| 3165 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3166 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3167 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3168 | * @hide |
| 3169 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3170 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3171 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3175 | * @hide |
| 3176 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3177 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3178 | if (mService != null) { |
| 3179 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3180 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3181 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3182 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3183 | } |
| 3184 | } |
| 3185 | } |
| 3186 | |
| 3187 | /** |
| 3188 | * @hide |
| 3189 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3190 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3191 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3192 | if (mService != null) { |
| 3193 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3194 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3195 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3196 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3197 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3198 | } |
| 3199 | } |
| 3200 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3201 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3202 | /** |
| 3203 | * @hide |
| 3204 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3205 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3206 | if (mService != null) { |
| 3207 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3208 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3209 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3210 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3214 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3215 | /** |
| 3216 | * @hide |
| 3217 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3218 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3219 | if (mService != null) { |
| 3220 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3221 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3222 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3223 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3227 | |
| 3228 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3229 | * @hide |
| 3230 | */ |
| 3231 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3232 | if (mService != null) { |
| 3233 | try { |
| 3234 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3235 | } catch (RemoteException e) { |
| 3236 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3237 | } |
| 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | /** |
| 3242 | * @hide |
| 3243 | */ |
| 3244 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3245 | if (mService != null) { |
| 3246 | try { |
| 3247 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3248 | } catch (RemoteException e) { |
| 3249 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3250 | } |
| 3251 | } |
| 3252 | } |
| 3253 | |
| 3254 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3255 | * Should be called when keyguard has been dismissed. |
| 3256 | * @hide |
| 3257 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3258 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3259 | if (mService != null) { |
| 3260 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3261 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3262 | } catch (RemoteException e) { |
| 3263 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3264 | } |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | /** |
| 3269 | * Should be called when keyguard view has been shown to the user. |
| 3270 | * @hide |
| 3271 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3272 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3273 | if (mService != null) { |
| 3274 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3275 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3276 | } catch (RemoteException e) { |
| 3277 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3278 | } |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3283 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3284 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3285 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3286 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3287 | * @return whether the package was successfully registered as the device owner. |
| 3288 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3289 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3290 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3291 | public boolean setDeviceOwner(ComponentName who) { |
| 3292 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | /** |
| 3296 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3297 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3298 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3299 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | /** |
| 3303 | * @hide |
| 3304 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3305 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3306 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | /** |
| 3310 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3311 | * Sets the given package as the device owner. The package must already be installed. There |
| 3312 | * must not already be a device owner. |
| 3313 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3314 | * this method. |
| 3315 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3316 | * 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] | 3317 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3318 | * @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] | 3319 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3320 | * @return whether the package was successfully registered as the device owner. |
| 3321 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3322 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3323 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3324 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3325 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3326 | if (mService != null) { |
| 3327 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3328 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3329 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3330 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3331 | } |
| 3332 | } |
| 3333 | return false; |
| 3334 | } |
| 3335 | |
| 3336 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3337 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3338 | * 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] | 3339 | * 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] | 3340 | * package is currently registered as the device owner app, pass in the package name from |
| 3341 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3342 | * 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] | 3343 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3344 | * the setup process. |
| 3345 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3346 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3347 | * @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] | 3348 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3349 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3350 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3351 | } |
| 3352 | |
| 3353 | /** |
| 3354 | * @return true if a package is registered as device owner, only when it's running on the |
| 3355 | * calling user. |
| 3356 | * |
| 3357 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3358 | * @hide |
| 3359 | */ |
| 3360 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3361 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3362 | } |
| 3363 | |
| 3364 | /** |
| 3365 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3366 | * user. |
| 3367 | * |
| 3368 | * <p>Requires the MANAGE_USERS permission. |
| 3369 | * |
| 3370 | * @hide |
| 3371 | */ |
| 3372 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3373 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3374 | } |
| 3375 | |
| 3376 | /** |
| 3377 | * @return device owner component name, only when it's running on the calling user. |
| 3378 | * |
| 3379 | * @hide |
| 3380 | */ |
| 3381 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3382 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3383 | } |
| 3384 | |
| 3385 | /** |
| 3386 | * @return device owner component name, even if it's running on a different user. |
| 3387 | * |
| 3388 | * <p>Requires the MANAGE_USERS permission. |
| 3389 | * |
| 3390 | * @hide |
| 3391 | */ |
| 3392 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3393 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3394 | } |
| 3395 | |
| 3396 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3397 | if (packageName == null) { |
| 3398 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3399 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3400 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3401 | if (deviceOwner == null) { |
| 3402 | return false; |
| 3403 | } |
| 3404 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3405 | } |
| 3406 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3407 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3408 | if (mService != null) { |
| 3409 | try { |
| 3410 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3411 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3412 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3418 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3419 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3420 | * no device owner. |
| 3421 | * |
| 3422 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3423 | * |
| 3424 | * @hide |
| 3425 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3426 | public int getDeviceOwnerUserId() { |
| 3427 | if (mService != null) { |
| 3428 | try { |
| 3429 | return mService.getDeviceOwnerUserId(); |
| 3430 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3431 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3432 | } |
| 3433 | } |
| 3434 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | /** |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3438 | * Clears the current device owner. The caller must be the device owner. |
| 3439 | * |
| 3440 | * This function should be used cautiously as once it is called it cannot |
| 3441 | * be undone. The device owner can only be set as a part of device setup |
| 3442 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3443 | * |
| 3444 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3445 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3446 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3447 | if (mService != null) { |
| 3448 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3449 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3450 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3451 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3452 | } |
| 3453 | } |
| 3454 | } |
| 3455 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3456 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3457 | * Returns the device owner package name, only if it's running on the calling user. |
| 3458 | * |
| 3459 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3460 | * |
| 3461 | * @hide |
| 3462 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3463 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3464 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3465 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3466 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3470 | * @return true if the device is managed by any device owner. |
| 3471 | * |
| 3472 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3473 | * |
| 3474 | * @hide |
| 3475 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3476 | public boolean isDeviceManaged() { |
| 3477 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3478 | } |
| 3479 | |
| 3480 | /** |
| 3481 | * Returns the device owner name. Note this method *will* return the device owner |
| 3482 | * name when it's running on a different user. |
| 3483 | * |
| 3484 | * <p>Requires the MANAGE_USERS permission. |
| 3485 | * |
| 3486 | * @hide |
| 3487 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3488 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3489 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3490 | if (mService != null) { |
| 3491 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3492 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3493 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3494 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3495 | } |
| 3496 | } |
| 3497 | return null; |
| 3498 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3499 | |
| 3500 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3501 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3502 | * @deprecated Do not use |
| 3503 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3504 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3505 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3506 | @SystemApi |
| 3507 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3508 | return null; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3512 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3513 | * @deprecated Do not use |
| 3514 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3515 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3516 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3517 | @SystemApi |
| 3518 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3519 | return null; |
| 3520 | } |
| 3521 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3522 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3523 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3524 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3525 | * Sets the given component as an active admin and registers the package as the profile |
| 3526 | * owner for this user. The package must already be installed and there shouldn't be |
| 3527 | * an existing profile owner registered for this user. Also, this method must be called |
| 3528 | * before the user setup has been completed. |
| 3529 | * <p> |
| 3530 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3531 | * MANAGE_DEVICE_ADMINS permission. |
| 3532 | * @param admin The component to register as an active admin and profile owner. |
| 3533 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3534 | * @return whether the admin was successfully registered as the profile owner. |
| 3535 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3536 | * the user has already been set up. |
| 3537 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3538 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3539 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3540 | throws IllegalArgumentException { |
| 3541 | if (mService != null) { |
| 3542 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3543 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3544 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3545 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3546 | } catch (RemoteException re) { |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3547 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3548 | } |
| 3549 | } |
| 3550 | return false; |
| 3551 | } |
| 3552 | |
| 3553 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3554 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 3555 | * be from the same package as the active profile owner for this user, otherwise a |
| 3556 | * SecurityException will be thrown. |
| 3557 | * |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3558 | * <p>This doesn't work for managed profile owners. |
| 3559 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3560 | * @param admin The component to remove as the profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3561 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3562 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3563 | if (mService != null) { |
| 3564 | try { |
| 3565 | mService.clearProfileOwner(admin); |
| 3566 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3567 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3573 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3574 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3575 | */ |
| 3576 | public boolean hasUserSetupCompleted() { |
| 3577 | if (mService != null) { |
| 3578 | try { |
| 3579 | return mService.hasUserSetupCompleted(); |
| 3580 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3581 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3582 | } |
| 3583 | } |
| 3584 | return true; |
| 3585 | } |
| 3586 | |
| 3587 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3588 | * @hide |
| 3589 | * 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] | 3590 | * already be installed. There must not already be a profile owner for this user. |
| 3591 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3592 | * this method. |
| 3593 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3594 | * - the caller is SYSTEM_UID. |
| 3595 | * - 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] | 3596 | * @param admin the component name to be registered as profile owner. |
| 3597 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3598 | * @param userHandle the userId to set the profile owner for. |
| 3599 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3600 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3601 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3602 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3603 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3604 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3605 | if (mService != null) { |
| 3606 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3607 | if (ownerName == null) { |
| 3608 | ownerName = ""; |
| 3609 | } |
| 3610 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3611 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3612 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3613 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3614 | } |
| 3615 | } |
| 3616 | return false; |
| 3617 | } |
| 3618 | |
| 3619 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3620 | * Sets the device owner information to be shown on the lock screen. |
| 3621 | * |
| 3622 | * <p>If the device owner information is {@code null} or empty then the device owner info is |
| 3623 | * 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] | 3624 | * <p>If the device owner information contains only whitespaces then the message on the lock |
| 3625 | * 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] | 3626 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 3627 | * <p>If the device owner information needs to be localized, it is the responsibility of the |
| 3628 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3629 | * and set a new version of this string accordingly. |
| 3630 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3631 | * @param admin The name of the admin component to check. |
| 3632 | * @param info Device owner information which will be displayed instead of the user |
| 3633 | * owner info. |
| 3634 | * @return Whether the device owner information has been set. |
| 3635 | */ |
| 3636 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3637 | if (mService != null) { |
| 3638 | try { |
| 3639 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3640 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3641 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3642 | } |
| 3643 | } |
| 3644 | return false; |
| 3645 | } |
| 3646 | |
| 3647 | /** |
| 3648 | * @return The device owner information. If it is not set returns {@code null}. |
| 3649 | */ |
| 3650 | public String getDeviceOwnerLockScreenInfo() { |
| 3651 | if (mService != null) { |
| 3652 | try { |
| 3653 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3654 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3655 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3656 | } |
| 3657 | } |
| 3658 | return null; |
| 3659 | } |
| 3660 | |
| 3661 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3662 | * Called by device or profile owners to suspend packages for this user. |
| 3663 | * |
| 3664 | * <p>A suspended package will not be able to start activities. Its notifications will |
| 3665 | * be hidden, it will not show up in recents, will not be able to show toasts or dialogs |
| 3666 | * or ring the device. |
| 3667 | * |
| 3668 | * <p>The package must already be installed. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3669 | * |
| 3670 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3671 | * @param packageNames The package names to suspend or unsuspend. |
| 3672 | * @param suspended If set to {@code true} than the packages will be suspended, if set to |
| 3673 | * {@code false} the packages will be unsuspended. |
| 3674 | * @return an array of package names for which the suspended status is not set as requested in |
| 3675 | * this method. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3676 | */ |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3677 | public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames, |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3678 | boolean suspended) { |
| 3679 | if (mService != null) { |
| 3680 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3681 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3682 | } catch (RemoteException re) { |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3683 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3684 | } |
| 3685 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3686 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | /** |
| 3690 | * Called by device or profile owners to determine if a package is suspended. |
| 3691 | * |
| 3692 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3693 | * @param packageName The name of the package to retrieve the suspended status of. |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 3694 | * @return {@code true} if the package is suspended or {@code false} if the package is not |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3695 | * suspended, could not be found or an error occurred. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3696 | */ |
| 3697 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3698 | if (mService != null) { |
| 3699 | try { |
| 3700 | return mService.getPackageSuspended(admin, packageName); |
| 3701 | } catch (RemoteException e) { |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3702 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | return false; |
| 3706 | } |
| 3707 | |
| 3708 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3709 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3710 | * be used. Only the profile owner can call this. |
| 3711 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3712 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3713 | * |
| 3714 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3715 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3716 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3717 | if (mService != null) { |
| 3718 | try { |
| 3719 | mService.setProfileEnabled(admin); |
| 3720 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3721 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3722 | } |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3727 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3728 | * 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] | 3729 | * never called by the profile or device owner, the name will be set to default values. |
| 3730 | * |
| 3731 | * @see #isProfileOwnerApp |
| 3732 | * @see #isDeviceOwnerApp |
| 3733 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3734 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3735 | * @param profileName The name of the profile. |
| 3736 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3737 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3738 | if (mService != null) { |
| 3739 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3740 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3741 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3742 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3743 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3744 | } |
| 3745 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3746 | |
| 3747 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3748 | * 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] | 3749 | * 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] | 3750 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3751 | * |
| 3752 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3753 | * @return Whether or not the package is registered as the profile owner. |
| 3754 | */ |
| 3755 | public boolean isProfileOwnerApp(String packageName) { |
| 3756 | if (mService != null) { |
| 3757 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 3758 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3759 | return profileOwner != null |
| 3760 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3761 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3762 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3763 | } |
| 3764 | } |
| 3765 | return false; |
| 3766 | } |
| 3767 | |
| 3768 | /** |
| 3769 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3770 | * @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] | 3771 | * owner has been set for that user. |
| 3772 | * @throws IllegalArgumentException if the userId is invalid. |
| 3773 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3774 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3775 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3776 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3777 | } |
| 3778 | |
| 3779 | /** |
| 3780 | * @see #getProfileOwner() |
| 3781 | * @hide |
| 3782 | */ |
| 3783 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3784 | if (mService != null) { |
| 3785 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3786 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3787 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3788 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3789 | throw new IllegalArgumentException( |
| 3790 | "Requested profile owner for invalid userId", re); |
| 3791 | } |
| 3792 | } |
| 3793 | return null; |
| 3794 | } |
| 3795 | |
| 3796 | /** |
| 3797 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3798 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3799 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3800 | * @throws IllegalArgumentException if the userId is invalid. |
| 3801 | */ |
| 3802 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3803 | if (mService != null) { |
| 3804 | try { |
| 3805 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3806 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3807 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3808 | throw new IllegalArgumentException( |
| 3809 | "Requested profile owner for invalid userId", re); |
| 3810 | } |
| 3811 | } |
| 3812 | return null; |
| 3813 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3814 | |
| 3815 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3816 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3817 | * @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] | 3818 | * @return the human readable name of the organisation associated with this profile owner or |
| 3819 | * null if one is not set. |
| 3820 | * @throws IllegalArgumentException if the userId is invalid. |
| 3821 | */ |
| 3822 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3823 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3824 | if (mService != null) { |
| 3825 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3826 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3827 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3828 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3829 | throw new IllegalArgumentException( |
| 3830 | "Requested profile owner for invalid userId", re); |
| 3831 | } |
| 3832 | } |
| 3833 | return null; |
| 3834 | } |
| 3835 | |
| 3836 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3837 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3838 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3839 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3840 | * the intent preferences are reset. |
| 3841 | * |
| 3842 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3843 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3844 | * intent handler for the filter. |
| 3845 | * |
| 3846 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3847 | * security exception will be thrown. |
| 3848 | * |
| 3849 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3850 | * @param filter The IntentFilter for which a default handler is added. |
| 3851 | * @param activity The Activity that is added as default intent handler. |
| 3852 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3853 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3854 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3855 | if (mService != null) { |
| 3856 | try { |
| 3857 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3858 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3859 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3860 | } |
| 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | /** |
| 3865 | * 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] | 3866 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3867 | * |
| 3868 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3869 | * exception will be thrown. |
| 3870 | * |
| 3871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3872 | * @param packageName The name of the package for which preferences are removed. |
| 3873 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3874 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3875 | String packageName) { |
| 3876 | if (mService != null) { |
| 3877 | try { |
| 3878 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3879 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3880 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3881 | } |
| 3882 | } |
| 3883 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3884 | |
| 3885 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3886 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 3887 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 3888 | * {@link #getApplicationRestrictions}. |
| 3889 | * <p> |
| 3890 | * This permission is persistent until it is later cleared by calling this method with a |
| 3891 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3892 | * <p> |
| 3893 | * The supplied application restriction managing package must be installed when calling this |
| 3894 | * API, otherwise an {@link IllegalArgumentException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3895 | * |
| 3896 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3897 | * @param packageName The package name which will be given access to application restrictions |
| 3898 | * APIs. If {@code null} is given the current package will be cleared. |
| 3899 | */ |
| 3900 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
| 3901 | @Nullable String packageName) { |
| 3902 | if (mService != null) { |
| 3903 | try { |
| 3904 | mService.setApplicationRestrictionsManagingPackage(admin, packageName); |
| 3905 | } catch (RemoteException e) { |
| 3906 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3907 | } |
| 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | /** |
| 3912 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 3913 | * package for the current user, or {@code null} if none is set. |
| 3914 | * |
| 3915 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3916 | * @return The package name allowed to manage application restrictions on the current user, or |
| 3917 | * {@code null} if none is set. |
| 3918 | */ |
| 3919 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 3920 | if (mService != null) { |
| 3921 | try { |
| 3922 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 3923 | } catch (RemoteException e) { |
| 3924 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3925 | } |
| 3926 | } |
| 3927 | return null; |
| 3928 | } |
| 3929 | |
| 3930 | /** |
| 3931 | * Returns {@code true} if the calling package has been granted permission via |
| 3932 | * {@link #setApplicationRestrictionsManagingPackage} to manage application |
| 3933 | * restrictions for the calling user. |
| 3934 | */ |
| 3935 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 3936 | if (mService != null) { |
| 3937 | try { |
| 3938 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 3939 | } catch (RemoteException e) { |
| 3940 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3941 | } |
| 3942 | } |
| 3943 | return false; |
| 3944 | } |
| 3945 | |
| 3946 | /** |
| 3947 | * Sets the application restrictions for a given target application running in the calling user. |
| 3948 | * |
| 3949 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 3950 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 3951 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3952 | * |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 3953 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
| 3954 | * <ul> |
| 3955 | * <li>{@code boolean} |
| 3956 | * <li>{@code int} |
| 3957 | * <li>{@code String} or {@code String[]} |
| 3958 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 3959 | * </ul> |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3960 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3961 | * <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] | 3962 | * the caller can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3963 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 3964 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3965 | * <p>The application restrictions are only made visible to the target application via |
| 3966 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or |
| 3967 | * device owner, and the application restrictions managing package via |
| 3968 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3969 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3970 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3971 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3972 | * @param packageName The name of the package to update restricted settings for. |
| 3973 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 3974 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3975 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3976 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3977 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3978 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3979 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3980 | Bundle settings) { |
| 3981 | if (mService != null) { |
| 3982 | try { |
| 3983 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3984 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3985 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3986 | } |
| 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3991 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3992 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3993 | * trust agents but those enabled by this function call. If flag |
| 3994 | * {@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] | 3995 | * |
| 3996 | * <p>The calling device admin must have requested |
| 3997 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3998 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3999 | * |
| 4000 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4001 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4002 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4003 | * will be strictly disabled according to the state of the |
| 4004 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4005 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 4006 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 4007 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4008 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4009 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4010 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4011 | if (mService != null) { |
| 4012 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4013 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4014 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4015 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4016 | } |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4021 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4022 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4023 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4024 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4025 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4026 | * this function returns a list of configurations for all admins that declare |
| 4027 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4028 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4029 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4030 | * 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] | 4031 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4032 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4033 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4034 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4035 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4036 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4040 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4041 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4042 | if (mService != null) { |
| 4043 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4044 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4045 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4046 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4047 | } |
| 4048 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4049 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4053 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 4054 | * 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] | 4055 | * |
| 4056 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4057 | * security exception will be thrown. |
| 4058 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4059 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4060 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 4061 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4062 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4063 | if (mService != null) { |
| 4064 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4065 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4066 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4067 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4073 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4074 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4075 | * |
| 4076 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4077 | * security exception will be thrown. |
| 4078 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4079 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4080 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4081 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4082 | if (mService != null) { |
| 4083 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4084 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4085 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4086 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | return false; |
| 4090 | } |
| 4091 | |
| 4092 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4093 | * Determine whether or not caller-Id information has been disabled. |
| 4094 | * |
| 4095 | * @param userHandle The user for whom to check the caller-id permission |
| 4096 | * @hide |
| 4097 | */ |
| 4098 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4099 | if (mService != null) { |
| 4100 | try { |
| 4101 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4102 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4103 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4104 | } |
| 4105 | } |
| 4106 | return false; |
| 4107 | } |
| 4108 | |
| 4109 | /** |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4110 | * Called by a profile owner of a managed profile to set whether contacts search from |
| 4111 | * the managed profile will be shown in the parent profile, for incoming calls. |
| 4112 | * |
| 4113 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4114 | * security exception will be thrown. |
| 4115 | * |
| 4116 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4117 | * @param disabled If true contacts search in the managed profile is not displayed. |
| 4118 | */ |
| 4119 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4120 | boolean disabled) { |
| 4121 | if (mService != null) { |
| 4122 | try { |
| 4123 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 4124 | } catch (RemoteException e) { |
| 4125 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4126 | } |
| 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | /** |
| 4131 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4132 | * has been disabled. |
| 4133 | * |
| 4134 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4135 | * security exception will be thrown. |
| 4136 | * |
| 4137 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4138 | */ |
| 4139 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 4140 | if (mService != null) { |
| 4141 | try { |
| 4142 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4143 | } catch (RemoteException e) { |
| 4144 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4145 | } |
| 4146 | } |
| 4147 | return false; |
| 4148 | } |
| 4149 | |
| 4150 | |
| 4151 | /** |
| 4152 | * Determine whether or not contacts search has been disabled. |
| 4153 | * |
| 4154 | * @param userHandle The user for whom to check the contacts search permission |
| 4155 | * @hide |
| 4156 | */ |
| 4157 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4158 | if (mService != null) { |
| 4159 | try { |
| 4160 | return mService |
| 4161 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4162 | } catch (RemoteException e) { |
| 4163 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4164 | } |
| 4165 | } |
| 4166 | return false; |
| 4167 | } |
| 4168 | |
| 4169 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4170 | * 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] | 4171 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4172 | * @hide |
| 4173 | */ |
| 4174 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4175 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4176 | if (mService != null) { |
| 4177 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4178 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 4179 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4180 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4181 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4182 | } |
| 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4187 | * 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] | 4188 | * @hide |
| 4189 | */ |
| 4190 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4191 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4192 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4193 | originalIntent); |
| 4194 | } |
| 4195 | |
| 4196 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4197 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 4198 | * devices can access enterprise contacts. |
| 4199 | * <p> |
| 4200 | * The calling device admin must be a profile owner. If it is not, a |
| 4201 | * security exception will be thrown. |
| 4202 | * <p> |
| 4203 | * This API works on managed profile only. |
| 4204 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4205 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4206 | * with. |
| 4207 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 4208 | * contacts. |
| 4209 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4210 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4211 | if (mService != null) { |
| 4212 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4213 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4214 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4215 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | /** |
| 4221 | * Called by a profile owner of a managed profile to determine whether or |
| 4222 | * not Bluetooth devices cannot access enterprise contacts. |
| 4223 | * <p> |
| 4224 | * The calling device admin must be a profile owner. If it is not, a |
| 4225 | * security exception will be thrown. |
| 4226 | * <p> |
| 4227 | * This API works on managed profile only. |
| 4228 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4229 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4230 | * with. |
| 4231 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4232 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4233 | if (mService != null) { |
| 4234 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4235 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4236 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4237 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4238 | } |
| 4239 | } |
| 4240 | return true; |
| 4241 | } |
| 4242 | |
| 4243 | /** |
| 4244 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4245 | * <p> |
| 4246 | * This API works on managed profile UserHandle only. |
| 4247 | * |
| 4248 | * @param userHandle The user for whom to check the caller-id permission |
| 4249 | * @hide |
| 4250 | */ |
| 4251 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4252 | if (mService != null) { |
| 4253 | try { |
| 4254 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4255 | .getIdentifier()); |
| 4256 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4257 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4258 | } |
| 4259 | } |
| 4260 | return true; |
| 4261 | } |
| 4262 | |
| 4263 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4264 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 4265 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4266 | * Only activity intents are supported. |
| 4267 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4268 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4269 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 4270 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4271 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 4272 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4273 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4274 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4275 | if (mService != null) { |
| 4276 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4277 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4278 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4279 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4280 | } |
| 4281 | } |
| 4282 | } |
| 4283 | |
| 4284 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4285 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4286 | * 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] | 4287 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4288 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4289 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4290 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4291 | if (mService != null) { |
| 4292 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4293 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4294 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4295 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4296 | } |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4301 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 4302 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4303 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 4304 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4305 | * By default the user can use any accessiblity service. When zero or more packages have |
| 4306 | * 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] | 4307 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4308 | * |
| 4309 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 4310 | * can be used, calling with an empty list only allows the builtin system's services. |
| 4311 | * |
| 4312 | * <p> System accesibility services are always available to the user the list can't modify |
| 4313 | * this. |
| 4314 | * |
| 4315 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4316 | * @param packageNames List of accessibility service package names. |
| 4317 | * |
| 4318 | * @return true if setting the restriction succeeded. It fail if there is |
| 4319 | * one or more non-system accessibility services enabled, that are not in the list. |
| 4320 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4321 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4322 | List<String> packageNames) { |
| 4323 | if (mService != null) { |
| 4324 | try { |
| 4325 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4326 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4327 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4328 | } |
| 4329 | } |
| 4330 | return false; |
| 4331 | } |
| 4332 | |
| 4333 | /** |
| 4334 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 4335 | * |
| 4336 | * <p>An empty list means no accessibility services except system services are allowed. |
| 4337 | * Null means all accessibility services are allowed. |
| 4338 | * |
| 4339 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4340 | * @return List of accessiblity service package names. |
| 4341 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4342 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4343 | if (mService != null) { |
| 4344 | try { |
| 4345 | return mService.getPermittedAccessibilityServices(admin); |
| 4346 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4347 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | return null; |
| 4351 | } |
| 4352 | |
| 4353 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4354 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4355 | * |
| 4356 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4357 | * @param packageName Accessibility service package name that needs to be checked. |
| 4358 | * @param userHandle user id the admin is running as. |
| 4359 | * @return true if the accessibility service is permitted, otherwise false. |
| 4360 | * |
| 4361 | * @hide |
| 4362 | */ |
| 4363 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4364 | @NonNull String packageName, int userHandle) { |
| 4365 | if (mService != null) { |
| 4366 | try { |
| 4367 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4368 | userHandle); |
| 4369 | } catch (RemoteException e) { |
| 4370 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4371 | } |
| 4372 | } |
| 4373 | return false; |
| 4374 | } |
| 4375 | |
| 4376 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4377 | * Returns the list of accessibility services permitted by the device or profiles |
| 4378 | * owners of this user. |
| 4379 | * |
| 4380 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4381 | * it will contain the intersection of the permitted lists for any device or profile |
| 4382 | * owners that apply to this user. It will also include any system accessibility services. |
| 4383 | * |
| 4384 | * @param userId which user to check for. |
| 4385 | * @return List of accessiblity service package names. |
| 4386 | * @hide |
| 4387 | */ |
| 4388 | @SystemApi |
| 4389 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4390 | if (mService != null) { |
| 4391 | try { |
| 4392 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4393 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4394 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4395 | } |
| 4396 | } |
| 4397 | return null; |
| 4398 | } |
| 4399 | |
| 4400 | /** |
| 4401 | * Called by a profile or device owner to set the permitted input methods services. When |
| 4402 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4403 | * user the device owner or profile owner is an admin for. |
| 4404 | * |
| 4405 | * By default the user can use any input method. When zero or more packages have |
| 4406 | * been added, input method that are not in the list and not part of the system |
| 4407 | * can not be enabled by the user. |
| 4408 | * |
| 4409 | * This method will fail if it is called for a admin that is not for the foreground user |
| 4410 | * or a profile of the foreground user. |
| 4411 | * |
| 4412 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 4413 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 4414 | * |
| 4415 | * <p> System input methods are always available to the user this method can't modify this. |
| 4416 | * |
| 4417 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4418 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 4419 | * @return true if setting the restriction succeeded. It will fail if there are |
| 4420 | * one or more non-system input methods currently enabled that are not in |
| 4421 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4422 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4423 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4424 | if (mService != null) { |
| 4425 | try { |
| 4426 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4427 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4428 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4429 | } |
| 4430 | } |
| 4431 | return false; |
| 4432 | } |
| 4433 | |
| 4434 | |
| 4435 | /** |
| 4436 | * Returns the list of permitted input methods set by this device or profile owner. |
| 4437 | * |
| 4438 | * <p>An empty list means no input methods except system input methods are allowed. |
| 4439 | * Null means all input methods are allowed. |
| 4440 | * |
| 4441 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4442 | * @return List of input method package names. |
| 4443 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4444 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4445 | if (mService != null) { |
| 4446 | try { |
| 4447 | return mService.getPermittedInputMethods(admin); |
| 4448 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4449 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | return null; |
| 4453 | } |
| 4454 | |
| 4455 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4456 | * Called by the system to check if a specific input method is disabled by admin. |
| 4457 | * |
| 4458 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4459 | * @param packageName Input method package name that needs to be checked. |
| 4460 | * @param userHandle user id the admin is running as. |
| 4461 | * @return true if the input method is permitted, otherwise false. |
| 4462 | * |
| 4463 | * @hide |
| 4464 | */ |
| 4465 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4466 | @NonNull String packageName, int userHandle) { |
| 4467 | if (mService != null) { |
| 4468 | try { |
| 4469 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4470 | } catch (RemoteException e) { |
| 4471 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4472 | } |
| 4473 | } |
| 4474 | return false; |
| 4475 | } |
| 4476 | |
| 4477 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4478 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4479 | * 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] | 4480 | * |
| 4481 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4482 | * it will contain the intersection of the permitted lists for any device or profile |
| 4483 | * owners that apply to this user. It will also include any system input methods. |
| 4484 | * |
| 4485 | * @return List of input method package names. |
| 4486 | * @hide |
| 4487 | */ |
| 4488 | @SystemApi |
| 4489 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4490 | if (mService != null) { |
| 4491 | try { |
| 4492 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4493 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4494 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4495 | } |
| 4496 | } |
| 4497 | return null; |
| 4498 | } |
| 4499 | |
| 4500 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4501 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4502 | * currently installed it. |
| 4503 | * |
| 4504 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4505 | * |
| 4506 | * @return List of package names to keep cached. |
| 4507 | * @hide |
| 4508 | */ |
| 4509 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4510 | if (mService != null) { |
| 4511 | try { |
| 4512 | return mService.getKeepUninstalledPackages(admin); |
| 4513 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4514 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4515 | } |
| 4516 | } |
| 4517 | return null; |
| 4518 | } |
| 4519 | |
| 4520 | /** |
| 4521 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4522 | * currently installed it. |
| 4523 | * |
| 4524 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4525 | * automatically pre-cached.</p> |
| 4526 | * |
| 4527 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4528 | * @param packageNames List of package names to keep cached. |
| 4529 | * @hide |
| 4530 | */ |
| 4531 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4532 | @NonNull List<String> packageNames) { |
| 4533 | if (mService != null) { |
| 4534 | try { |
| 4535 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4536 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4537 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4538 | } |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4543 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4544 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4545 | * created. If you need to persist an identifier for this user, use |
| 4546 | * {@link UserManager#getSerialNumberForUser}. |
| 4547 | * |
| 4548 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4549 | * @param name the user's name |
| 4550 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4551 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4552 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4553 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4554 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4555 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4556 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4557 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4558 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4559 | return null; |
| 4560 | } |
| 4561 | |
| 4562 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4563 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4564 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4565 | * created. If you need to persist an identifier for this user, use |
| 4566 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4567 | * immediately. |
| 4568 | * |
| 4569 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4570 | * as registered as an active admin on the new user. The profile owner package will be |
| 4571 | * installed on the new user if it already is installed on the device. |
| 4572 | * |
| 4573 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4574 | * profileOwnerComponent when onEnable is called. |
| 4575 | * |
| 4576 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4577 | * @param name the user's name |
| 4578 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4579 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4580 | * the user. |
| 4581 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4582 | * on the new user. |
| 4583 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4584 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4585 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4586 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4587 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4588 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4589 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4590 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4591 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4592 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4593 | return null; |
| 4594 | } |
| 4595 | |
| 4596 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4597 | * 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] | 4598 | */ |
| 4599 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4600 | |
| 4601 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4602 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4603 | * ephemeral. |
| 4604 | * @hide |
| 4605 | */ |
| 4606 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4607 | |
| 4608 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4609 | * Called by a device owner to create a user with the specified name and a given component of |
| 4610 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4611 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4612 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4613 | * user will not be started in the background. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4614 | * |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4615 | * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also |
| 4616 | * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and |
| 4617 | * will be registered as an active admin on the new user. The profile owner package will be |
| 4618 | * installed on the new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4619 | * |
| 4620 | * <p>If the adminExtras are not null, they will be stored on the device until the user is |
| 4621 | * started for the first time. Then the extras will be passed to the admin when |
| 4622 | * onEnable is called. |
| 4623 | * |
| 4624 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4625 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4626 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
| 4627 | * same package as admin, otherwise no user is created and an IllegalArgumentException is |
| 4628 | * thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4629 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
| 4630 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4631 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4632 | * @see UserHandle |
| 4633 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4634 | * user could not be created. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4635 | */ |
| 4636 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4637 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4638 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4639 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4640 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4641 | } catch (RemoteException re) { |
| 4642 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 4643 | } |
| 4644 | return null; |
| 4645 | } |
| 4646 | |
| 4647 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4648 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 4649 | * not be removed. |
| 4650 | * |
| 4651 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4652 | * @param userHandle the user to remove. |
| 4653 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 4654 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4655 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4656 | try { |
| 4657 | return mService.removeUser(admin, userHandle); |
| 4658 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4659 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4660 | return false; |
| 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4665 | * Called by a device owner to switch the specified user to the foreground. |
| 4666 | * |
| 4667 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4668 | * @param userHandle the user to switch to; null will switch to primary. |
| 4669 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 4670 | * |
| 4671 | * @see Intent#ACTION_USER_FOREGROUND |
| 4672 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4673 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4674 | try { |
| 4675 | return mService.switchUser(admin, userHandle); |
| 4676 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4677 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4678 | return false; |
| 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4683 | * Retrieves the application restrictions for a given target application running in the calling |
| 4684 | * user. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4685 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4686 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4687 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4688 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4689 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4690 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4691 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4692 | * @param packageName The name of the package to fetch restricted settings of. |
| 4693 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 4694 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 4695 | * if no restrictions have been set. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4696 | * |
| 4697 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4698 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4699 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4700 | if (mService != null) { |
| 4701 | try { |
| 4702 | return mService.getApplicationRestrictions(admin, packageName); |
| 4703 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4704 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4705 | } |
| 4706 | } |
| 4707 | return null; |
| 4708 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4709 | |
| 4710 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4711 | * 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] | 4712 | * <p> |
| 4713 | * The calling device admin must be a profile or device owner; if it is not, |
| 4714 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4715 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4716 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4717 | * with. |
| 4718 | * @param key The key of the restriction. See the constants in |
| 4719 | * {@link android.os.UserManager} for the list of keys. |
| 4720 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4721 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4722 | if (mService != null) { |
| 4723 | try { |
| 4724 | mService.setUserRestriction(admin, key, true); |
| 4725 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4726 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4732 | * 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] | 4733 | * <p> |
| 4734 | * The calling device admin must be a profile or device owner; if it is not, |
| 4735 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4736 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4737 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4738 | * with. |
| 4739 | * @param key The key of the restriction. See the constants in |
| 4740 | * {@link android.os.UserManager} for the list of keys. |
| 4741 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4742 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4743 | if (mService != null) { |
| 4744 | try { |
| 4745 | mService.setUserRestriction(admin, key, false); |
| 4746 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4747 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4748 | } |
| 4749 | } |
| 4750 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4751 | |
| 4752 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4753 | * Called by a profile or device owner to get user restrictions set with |
| 4754 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4755 | * <p> |
| 4756 | * The target user may have more restrictions set by the system or other device owner / profile |
| 4757 | * owner. To get all the user restrictions currently set, use |
| 4758 | * {@link UserManager#getUserRestrictions()}. |
| 4759 | * |
| 4760 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4761 | * @throws SecurityException if the {@code admin} is not an active admin. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4762 | */ |
| 4763 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4764 | return getUserRestrictions(admin, myUserId()); |
| 4765 | } |
| 4766 | |
| 4767 | /** @hide per-user version */ |
| 4768 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4769 | Bundle ret = null; |
| 4770 | if (mService != null) { |
| 4771 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4772 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4773 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4774 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | return ret == null ? new Bundle() : ret; |
| 4778 | } |
| 4779 | |
| 4780 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4781 | * 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] | 4782 | * is unavailable for use, but the data and actual package file remain. |
| 4783 | * |
| 4784 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4785 | * @param packageName The name of the package to hide or unhide. |
| 4786 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 4787 | * unhidden. |
| 4788 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4789 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4790 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4791 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4792 | if (mService != null) { |
| 4793 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4794 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4795 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4796 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | return false; |
| 4800 | } |
| 4801 | |
| 4802 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4803 | * 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] | 4804 | * |
| 4805 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4806 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4807 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4808 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4809 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4810 | if (mService != null) { |
| 4811 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4812 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4813 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4814 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4815 | } |
| 4816 | } |
| 4817 | return false; |
| 4818 | } |
| 4819 | |
| 4820 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4821 | * 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] | 4822 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4823 | * |
| 4824 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4825 | * @param packageName The package to be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4826 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4827 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4828 | if (mService != null) { |
| 4829 | try { |
| 4830 | mService.enableSystemApp(admin, packageName); |
| 4831 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4832 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4833 | } |
| 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4838 | * 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] | 4839 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4840 | * |
| 4841 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4842 | * @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] | 4843 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4844 | * @return int The number of activities that matched the intent and were installed. |
| 4845 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4846 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4847 | if (mService != null) { |
| 4848 | try { |
| 4849 | return mService.enableSystemAppWithIntent(admin, intent); |
| 4850 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4851 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4852 | } |
| 4853 | } |
| 4854 | return 0; |
| 4855 | } |
| 4856 | |
| 4857 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4858 | * Called by a device owner or profile owner to disable account management for a specific type |
| 4859 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4860 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4861 | * <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] | 4862 | * security exception will be thrown. |
| 4863 | * |
| 4864 | * <p>When account management is disabled for an account type, adding or removing an account |
| 4865 | * of that type will not be possible. |
| 4866 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 4867 | * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
| 4868 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 4869 | * management for a specific type is disabled. |
| 4870 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4872 | * @param accountType For which account management is disabled or enabled. |
| 4873 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 4874 | * enabled (false). |
| 4875 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4876 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4877 | boolean disabled) { |
| 4878 | if (mService != null) { |
| 4879 | try { |
| 4880 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 4881 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4882 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4883 | } |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4888 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 4889 | * |
| 4890 | * <p> Account management can be disabled/enabled by calling |
| 4891 | * {@link #setAccountManagementDisabled}. |
| 4892 | * |
| 4893 | * @return a list of account types for which account management has been disabled. |
| 4894 | * |
| 4895 | * @see #setAccountManagementDisabled |
| 4896 | */ |
| 4897 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4898 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4899 | } |
| 4900 | |
| 4901 | /** |
| 4902 | * @see #getAccountTypesWithManagementDisabled() |
| 4903 | * @hide |
| 4904 | */ |
| 4905 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4906 | if (mService != null) { |
| 4907 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4908 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4909 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4910 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4911 | } |
| 4912 | } |
| 4913 | |
| 4914 | return null; |
| 4915 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4916 | |
| 4917 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4918 | * Sets which packages may enter lock task mode. |
| 4919 | * |
| 4920 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 4921 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4922 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4923 | * 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] | 4924 | * package list results in locked tasks belonging to those packages to be finished. |
| 4925 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 4926 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4927 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4928 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4929 | * |
| 4930 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 4931 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 4932 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 4933 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4934 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4935 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4936 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4937 | if (mService != null) { |
| 4938 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4939 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4940 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4941 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4942 | } |
| 4943 | } |
| 4944 | } |
| 4945 | |
| 4946 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4947 | * 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] | 4948 | * |
| 4949 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4950 | * @hide |
| 4951 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4952 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4953 | if (mService != null) { |
| 4954 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4955 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4956 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4957 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4958 | } |
| 4959 | } |
| 4960 | return null; |
| 4961 | } |
| 4962 | |
| 4963 | /** |
| 4964 | * This function lets the caller know whether the given component is allowed to start the |
| 4965 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4966 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4967 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4968 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4969 | if (mService != null) { |
| 4970 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4971 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4972 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4973 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4974 | } |
| 4975 | } |
| 4976 | return false; |
| 4977 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4978 | |
| 4979 | /** |
| 4980 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 4981 | * 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] | 4982 | * <p>The settings that can be updated with this method are: |
| 4983 | * <ul> |
| 4984 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 4985 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 4986 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4987 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4988 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4989 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 4990 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4991 | * 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] | 4992 | * 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] | 4993 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4994 | * 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] | 4995 | * </li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4996 | * </ul> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4997 | * <p>Changing the following settings has no effect as of |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4998 | * {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4999 | * <ul> |
| 5000 | * <li>{@link Settings.Global#BLUETOOTH_ON}. |
| 5001 | * Use {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5002 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
| 5003 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 5004 | * <li>{@link Settings.Global#MODE_RINGER}. |
| 5005 | * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
| 5006 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 5007 | * <li>{@link Settings.Global#WIFI_ON}. |
| 5008 | * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
| 5009 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5010 | * |
| 5011 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5012 | * @param setting The name of the setting to update. |
| 5013 | * @param value The value to update the setting to. |
| 5014 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5015 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5016 | if (mService != null) { |
| 5017 | try { |
| 5018 | mService.setGlobalSetting(admin, setting, value); |
| 5019 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5020 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5021 | } |
| 5022 | } |
| 5023 | } |
| 5024 | |
| 5025 | /** |
| 5026 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5027 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5028 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5029 | * <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] | 5030 | * <ul> |
| 5031 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5032 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5033 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5034 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5035 | * <p>A device owner can additionally update the following settings: |
| 5036 | * <ul> |
| 5037 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5038 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5039 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5040 | * @param setting The name of the setting to update. |
| 5041 | * @param value The value to update the setting to. |
| 5042 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5043 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5044 | if (mService != null) { |
| 5045 | try { |
| 5046 | mService.setSecureSetting(admin, setting, value); |
| 5047 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5048 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5049 | } |
| 5050 | } |
| 5051 | } |
| 5052 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5053 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5054 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5055 | * making permission requests of a local or remote administrator of the user. |
| 5056 | * <p/> |
| 5057 | * Only a profile owner can designate the restrictions provider. |
| 5058 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5059 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 5060 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5061 | * it removes the restrictions provider previously assigned. |
| 5062 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5063 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5064 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5065 | if (mService != null) { |
| 5066 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5067 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5068 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5069 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5070 | } |
| 5071 | } |
| 5072 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5073 | |
| 5074 | /** |
| 5075 | * Called by profile or device owners to set the master volume mute on or off. |
| 5076 | * |
| 5077 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5078 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 5079 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5080 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5081 | if (mService != null) { |
| 5082 | try { |
| 5083 | mService.setMasterVolumeMuted(admin, on); |
| 5084 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5085 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5086 | } |
| 5087 | } |
| 5088 | } |
| 5089 | |
| 5090 | /** |
| 5091 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5092 | * |
| 5093 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5094 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 5095 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5096 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5097 | if (mService != null) { |
| 5098 | try { |
| 5099 | return mService.isMasterVolumeMuted(admin); |
| 5100 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5101 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | return false; |
| 5105 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5106 | |
| 5107 | /** |
| 5108 | * Called by profile or device owners to change whether a user can uninstall |
| 5109 | * a package. |
| 5110 | * |
| 5111 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5112 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5113 | * @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] | 5114 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5115 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5116 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5117 | if (mService != null) { |
| 5118 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5119 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5120 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5121 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5122 | } |
| 5123 | } |
| 5124 | } |
| 5125 | |
| 5126 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5127 | * 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] | 5128 | * 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] | 5129 | * <p> |
| 5130 | * <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] | 5131 | * 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] | 5132 | * 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] | 5133 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5134 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5135 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 5136 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5137 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5138 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5139 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5140 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5141 | if (mService != null) { |
| 5142 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 5143 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5144 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5145 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5146 | } |
| 5147 | } |
| 5148 | return false; |
| 5149 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5150 | |
| 5151 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5152 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 5153 | * 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] | 5154 | * 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] | 5155 | * 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] | 5156 | * a package may have zero or more provider components, where each component |
| 5157 | * provides a different widget type. |
| 5158 | * <p> |
| 5159 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5160 | * |
| 5161 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5162 | * @param packageName The package from which widget providers are white-listed. |
| 5163 | * @return Whether the package was added. |
| 5164 | * |
| 5165 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5166 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5167 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5168 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5169 | if (mService != null) { |
| 5170 | try { |
| 5171 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 5172 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5173 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5174 | } |
| 5175 | } |
| 5176 | return false; |
| 5177 | } |
| 5178 | |
| 5179 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5180 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 5181 | * 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] | 5182 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 5183 | * android.content.ComponentName, String)}. |
| 5184 | * <p> |
| 5185 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5186 | * |
| 5187 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5188 | * @param packageName The package from which widget providers are no longer |
| 5189 | * white-listed. |
| 5190 | * @return Whether the package was removed. |
| 5191 | * |
| 5192 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5193 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5194 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5195 | public boolean removeCrossProfileWidgetProvider( |
| 5196 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5197 | if (mService != null) { |
| 5198 | try { |
| 5199 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5200 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5201 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5202 | } |
| 5203 | } |
| 5204 | return false; |
| 5205 | } |
| 5206 | |
| 5207 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5208 | * 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] | 5209 | * available in the parent profile. |
| 5210 | * |
| 5211 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5212 | * @return The white-listed package list. |
| 5213 | * |
| 5214 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5215 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5216 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5217 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5218 | if (mService != null) { |
| 5219 | try { |
| 5220 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5221 | if (providers != null) { |
| 5222 | return providers; |
| 5223 | } |
| 5224 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5225 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5226 | } |
| 5227 | } |
| 5228 | return Collections.emptyList(); |
| 5229 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5230 | |
| 5231 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5232 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5233 | * |
| 5234 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5235 | * @param icon the bitmap to set as the photo. |
| 5236 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5237 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5238 | try { |
| 5239 | mService.setUserIcon(admin, icon); |
| 5240 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5241 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5242 | } |
| 5243 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5244 | |
| 5245 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5246 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5247 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5248 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5249 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 5250 | * components in the device owner package can set system update policies and the |
| 5251 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5252 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5253 | * @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] | 5254 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5255 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5256 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5257 | if (mService != null) { |
| 5258 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5259 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5260 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5261 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5262 | } |
| 5263 | } |
| 5264 | } |
| 5265 | |
| 5266 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5267 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5268 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5269 | * @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] | 5270 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5271 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5272 | if (mService != null) { |
| 5273 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5274 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5275 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5276 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5277 | } |
| 5278 | } |
| 5279 | return null; |
| 5280 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5281 | |
| 5282 | /** |
| 5283 | * Called by a device owner to disable the keyguard altogether. |
| 5284 | * |
| 5285 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 5286 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 5287 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 5288 | * being disabled. |
| 5289 | * |
| 5290 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5291 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5292 | * |
| 5293 | * @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] | 5294 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5295 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5296 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5297 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5298 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5299 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5300 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5301 | return false; |
| 5302 | } |
| 5303 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5304 | |
| 5305 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5306 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 5307 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5308 | * a single use device. |
| 5309 | * |
| 5310 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5311 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 5312 | * |
| 5313 | * @return {@code false} if attempting to disable the status bar failed. |
| 5314 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5315 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5316 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5317 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5318 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5319 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5320 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5321 | return false; |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5322 | } |
| 5323 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5324 | |
| 5325 | /** |
| 5326 | * Callable by the system update service to notify device owners about pending updates. |
| 5327 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5328 | * permission. |
| 5329 | * |
| 5330 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5331 | * when the current pending update was first available. -1 if no update is available. |
| 5332 | * @hide |
| 5333 | */ |
| 5334 | @SystemApi |
| 5335 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5336 | if (mService != null) { |
| 5337 | try { |
| 5338 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5339 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5340 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5341 | } |
| 5342 | } |
| 5343 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5344 | |
| 5345 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5346 | * Called by profile or device owners to set the default response for future runtime permission |
| 5347 | * requests by applications. The policy can allow for normal operation which prompts the |
| 5348 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 5349 | * 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] | 5350 | * updates. When a permission is denied or granted this way, the effect is equivalent to setting |
| 5351 | * the permission grant state via {@link #setPermissionGrantState}. |
| 5352 | * |
| 5353 | * <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] | 5354 | * 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] | 5355 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5356 | * @param admin Which profile or device owner this request is associated with. |
| 5357 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 5358 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5359 | * |
| 5360 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5361 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5362 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5363 | try { |
| 5364 | mService.setPermissionPolicy(admin, policy); |
| 5365 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5366 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5367 | } |
| 5368 | } |
| 5369 | |
| 5370 | /** |
| 5371 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5372 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5373 | * @param admin Which profile or device owner this request is associated with. |
| 5374 | * @return the current policy for future permission requests. |
| 5375 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5376 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5377 | try { |
| 5378 | return mService.getPermissionPolicy(admin); |
| 5379 | } catch (RemoteException re) { |
| 5380 | return PERMISSION_POLICY_PROMPT; |
| 5381 | } |
| 5382 | } |
| 5383 | |
| 5384 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5385 | * Sets the grant state of a runtime permission for a specific application. The state |
| 5386 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 5387 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 5388 | * is denied and the user cannot manage it through the UI, and {@link |
| 5389 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 5390 | * user cannot manage it through the UI. This might affect all permissions in a |
| 5391 | * group that the runtime permission belongs to. This method can only be called |
| 5392 | * by a profile or device owner. |
| 5393 | * |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5394 | * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not |
| 5395 | * revoke the permission. It retains the previous grant, if any. |
| 5396 | * |
| 5397 | * <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] | 5398 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5399 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5400 | * @param admin Which profile or device owner this request is associated with. |
| 5401 | * @param packageName The application to grant or revoke a permission to. |
| 5402 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5403 | * @param grantState The permission grant state which is one of {@link |
| 5404 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5405 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5406 | * @return whether the permission was successfully granted or revoked. |
| 5407 | * |
| 5408 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5409 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5410 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5411 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5412 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5413 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5414 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5415 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5416 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5417 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5418 | return false; |
| 5419 | } |
| 5420 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5421 | |
| 5422 | /** |
| 5423 | * Returns the current grant state of a runtime permission for a specific application. |
| 5424 | * |
| 5425 | * @param admin Which profile or device owner this request is associated with. |
| 5426 | * @param packageName The application to check the grant state for. |
| 5427 | * @param permission The permission to check for. |
| 5428 | * @return the current grant state specified by device policy. If the profile or device owner |
| 5429 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 5430 | * This does not indicate whether or not the permission is currently granted for the package. |
| 5431 | * |
| 5432 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 5433 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5434 | * which indicates if the permission is currently denied or granted. |
| 5435 | * |
| 5436 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5437 | * @see PackageManager#checkPermission(String, String) |
| 5438 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5439 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5440 | String permission) { |
| 5441 | try { |
| 5442 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5443 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5444 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5445 | return PERMISSION_GRANT_STATE_DEFAULT; |
| 5446 | } |
| 5447 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5448 | |
| 5449 | /** |
| 5450 | * Returns if provisioning a managed profile or device is possible or not. |
| 5451 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5452 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 5453 | * Note that even if this method returns true, there is a slight possibility that the |
| 5454 | * provisioning will not be allowed when it is actually initiated because some event has |
| 5455 | * happened in between. |
| 5456 | * @return if provisioning a managed profile or device is possible or not. |
| 5457 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5458 | */ |
| 5459 | public boolean isProvisioningAllowed(String action) { |
| 5460 | try { |
| 5461 | return mService.isProvisioningAllowed(action); |
| 5462 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5463 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5464 | return false; |
| 5465 | } |
| 5466 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5467 | |
| 5468 | /** |
| 5469 | * @hide |
| 5470 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5471 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5472 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5473 | * @param admin Which profile owner this request is associated with. |
| 5474 | * @return if this user is a managed profile of another user. |
| 5475 | */ |
| 5476 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5477 | try { |
| 5478 | return mService.isManagedProfile(admin); |
| 5479 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5480 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5481 | return false; |
| 5482 | } |
| 5483 | } |
| 5484 | |
| 5485 | /** |
| 5486 | * @hide |
| 5487 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5488 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5489 | * @param admin Which device owner this request is associated with. |
| 5490 | * @return if this user is a system-only user. |
| 5491 | */ |
| 5492 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5493 | try { |
| 5494 | return mService.isSystemOnlyUser(admin); |
| 5495 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5496 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5497 | return false; |
| 5498 | } |
| 5499 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5500 | |
| 5501 | /** |
| 5502 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5503 | * |
| 5504 | * @return the MAC address of the Wi-Fi device, or null when the information is not |
| 5505 | * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5506 | * |
| 5507 | * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5508 | */ |
| 5509 | public String getWifiMacAddress() { |
| 5510 | try { |
| 5511 | return mService.getWifiMacAddress(); |
| 5512 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5513 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5514 | return null; |
| 5515 | } |
| 5516 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5517 | |
| 5518 | /** |
| 5519 | * Called by device owner to reboot the device. |
| 5520 | */ |
| 5521 | public void reboot(@NonNull ComponentName admin) { |
| 5522 | try { |
| 5523 | mService.reboot(admin); |
| 5524 | } catch (RemoteException re) { |
| 5525 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5526 | } |
| 5527 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5528 | |
| 5529 | /** |
| 5530 | * Called by a device admin to set the short support message. This will |
| 5531 | * be displayed to the user in settings screens where funtionality has |
| 5532 | * been disabled by the admin. |
| 5533 | * |
| 5534 | * The message should be limited to a short statement such as |
| 5535 | * "This setting is disabled by your administrator. Contact someone@example.com |
| 5536 | * for support." |
| 5537 | * If the message is longer than 200 characters it may be truncated. |
| 5538 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5539 | * <p>If the short support message needs to be localized, it is the responsibility of the |
| 5540 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5541 | * and set a new version of this string accordingly. |
| 5542 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5543 | * @see #setLongSupportMessage |
| 5544 | * |
| 5545 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5546 | * @param message Short message to be displayed to the user in settings or null to |
| 5547 | * clear the existing message. |
| 5548 | */ |
| 5549 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5550 | @Nullable String message) { |
| 5551 | if (mService != null) { |
| 5552 | try { |
| 5553 | mService.setShortSupportMessage(admin, message); |
| 5554 | } catch (RemoteException e) { |
| 5555 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5556 | } |
| 5557 | } |
| 5558 | } |
| 5559 | |
| 5560 | /** |
| 5561 | * Called by a device admin to get the short support message. |
| 5562 | * |
| 5563 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5564 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5565 | * or null if no message has been set. |
| 5566 | */ |
| 5567 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5568 | if (mService != null) { |
| 5569 | try { |
| 5570 | return mService.getShortSupportMessage(admin); |
| 5571 | } catch (RemoteException e) { |
| 5572 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5573 | } |
| 5574 | } |
| 5575 | return null; |
| 5576 | } |
| 5577 | |
| 5578 | /** |
| 5579 | * Called by a device admin to set the long support message. This will |
| 5580 | * be displayed to the user in the device administators settings screen. |
| 5581 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5582 | * <p>If the long support message needs to be localized, it is the responsibility of the |
| 5583 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5584 | * and set a new version of this string accordingly. |
| 5585 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5586 | * @see #setShortSupportMessage |
| 5587 | * |
| 5588 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5589 | * @param message Long message to be displayed to the user in settings or null to |
| 5590 | * clear the existing message. |
| 5591 | */ |
| 5592 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5593 | @Nullable String message) { |
| 5594 | if (mService != null) { |
| 5595 | try { |
| 5596 | mService.setLongSupportMessage(admin, message); |
| 5597 | } catch (RemoteException e) { |
| 5598 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5599 | } |
| 5600 | } |
| 5601 | } |
| 5602 | |
| 5603 | /** |
| 5604 | * Called by a device admin to get the long support message. |
| 5605 | * |
| 5606 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5607 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5608 | * or null if no message has been set. |
| 5609 | */ |
| 5610 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5611 | if (mService != null) { |
| 5612 | try { |
| 5613 | return mService.getLongSupportMessage(admin); |
| 5614 | } catch (RemoteException e) { |
| 5615 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5616 | } |
| 5617 | } |
| 5618 | return null; |
| 5619 | } |
| 5620 | |
| 5621 | /** |
| 5622 | * Called by the system to get the short support message. |
| 5623 | * |
| 5624 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5625 | * @param userHandle user id the admin is running as. |
| 5626 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5627 | * |
| 5628 | * @hide |
| 5629 | */ |
| 5630 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5631 | if (mService != null) { |
| 5632 | try { |
| 5633 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5634 | } catch (RemoteException e) { |
| 5635 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5636 | } |
| 5637 | } |
| 5638 | return null; |
| 5639 | } |
| 5640 | |
| 5641 | |
| 5642 | /** |
| 5643 | * Called by the system to get the long support message. |
| 5644 | * |
| 5645 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5646 | * @param userHandle user id the admin is running as. |
| 5647 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5648 | * |
| 5649 | * @hide |
| 5650 | */ |
| 5651 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5652 | if (mService != null) { |
| 5653 | try { |
| 5654 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5655 | } catch (RemoteException e) { |
| 5656 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5657 | } |
| 5658 | } |
| 5659 | return null; |
| 5660 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5661 | |
| 5662 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5663 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5664 | * whose calls act on the parent profile. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5665 | * |
| 5666 | * <p> Note only some methods will work on the parent Manager. |
| 5667 | * |
| 5668 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
| 5669 | */ |
| 5670 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5671 | try { |
| 5672 | if (!mService.isManagedProfile(admin)) { |
| 5673 | throw new SecurityException("The current user does not have a parent profile."); |
| 5674 | } |
| 5675 | return new DevicePolicyManager(mContext, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5676 | } catch (RemoteException e) { |
| 5677 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5678 | return null; |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | /** |
| 5683 | * Called by device owner to control the device logging feature. Logging can only be |
| 5684 | * enabled on single user devices where the sole user is managed by the device owner. |
| 5685 | * |
| 5686 | * <p> Device logs contain various information intended for security auditing purposes. |
| 5687 | * See {@link SecurityEvent} for details. |
| 5688 | * |
| 5689 | * @param admin Which device owner this request is associated with. |
| 5690 | * @param enabled whether device logging should be enabled or not. |
| 5691 | * @see #retrieveDeviceLogs |
| 5692 | */ |
| 5693 | public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 5694 | try { |
| 5695 | mService.setDeviceLoggingEnabled(admin, enabled); |
| 5696 | } catch (RemoteException re) { |
| 5697 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5698 | } |
| 5699 | } |
| 5700 | |
| 5701 | /** |
| 5702 | * Return whether device logging is enabled or not by the device owner. |
| 5703 | * |
| 5704 | * @param admin Which device owner this request is associated with. |
| 5705 | * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise. |
| 5706 | */ |
| 5707 | public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) { |
| 5708 | try { |
| 5709 | return mService.getDeviceLoggingEnabled(admin); |
| 5710 | } catch (RemoteException re) { |
| 5711 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5712 | return false; |
| 5713 | } |
| 5714 | } |
| 5715 | |
| 5716 | /** |
| 5717 | * Called by device owner to retrieve all new device logging entries since the last call to |
| 5718 | * this API after device boots. |
| 5719 | * |
| 5720 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 5721 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 5722 | * |
| 5723 | * @param admin Which device owner this request is associated with. |
| 5724 | * @return the new batch of device logs which is a list of {@link SecurityEvent}, |
| 5725 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
| 5726 | */ |
| 5727 | public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) { |
| 5728 | try { |
| 5729 | ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin); |
| 5730 | if (list != null) { |
| 5731 | return list.getList(); |
| 5732 | } else { |
| 5733 | // Rate limit exceeded. |
| 5734 | return null; |
| 5735 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5736 | } catch (RemoteException re) { |
| 5737 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5738 | return null; |
| 5739 | } |
| 5740 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5741 | |
| 5742 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 5743 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 5744 | * profile. |
| 5745 | * |
| 5746 | * @hide |
| 5747 | */ |
| 5748 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 5749 | mContext.checkSelfPermission( |
| 5750 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 5751 | if (!uInfo.isManagedProfile()) { |
| 5752 | throw new SecurityException("The user " + uInfo.id |
| 5753 | + " does not have a parent profile."); |
| 5754 | } |
| 5755 | return new DevicePolicyManager(mContext, true); |
| 5756 | } |
| 5757 | |
| 5758 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5759 | * Called by device owners to retrieve device logs from before the device's last reboot. |
| 5760 | * |
| 5761 | * <p> |
| 5762 | * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be |
| 5763 | * corruption-free during power cycles, due to hardware variations and limitations. As a |
| 5764 | * result, this API is provided as best-effort and the returned logs may contain corrupted data. |
| 5765 | * </strong> |
| 5766 | * |
| 5767 | * @param admin Which device owner this request is associated with. |
| 5768 | * @return Device logs from before the latest reboot of the system. |
| 5769 | */ |
| 5770 | public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) { |
| 5771 | try { |
| 5772 | ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin); |
| 5773 | return list.getList(); |
| 5774 | } catch (RemoteException re) { |
| 5775 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5776 | return Collections.<SecurityEvent>emptyList(); |
| 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5781 | * Called by a profile owner of a managed profile to set the color used for customization. |
| 5782 | * This color is used as background color of the confirm credentials screen for that user. |
| 5783 | * The default color is {@link android.graphics.Color#GRAY}. |
| 5784 | * |
| 5785 | * <p>The confirm credentials screen can be created using |
| 5786 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5787 | * |
| 5788 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5789 | * @param color The 32bit representation of the color to be used. |
| 5790 | */ |
| 5791 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5792 | try { |
| 5793 | mService.setOrganizationColor(admin, color); |
| 5794 | } catch (RemoteException re) { |
| 5795 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 5800 | * @hide |
| 5801 | * |
| 5802 | * Sets the color used for customization. |
| 5803 | * |
| 5804 | * @param color The 32bit representation of the color to be used. |
| 5805 | * @param userId which user to set the color to. |
| 5806 | * @RequiresPermission(allOf = { |
| 5807 | * Manifest.permission.MANAGE_USERS, |
| 5808 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 5809 | */ |
| 5810 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 5811 | try { |
| 5812 | mService.setOrganizationColorForUser(color, userId); |
| 5813 | } catch (RemoteException re) { |
| 5814 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5819 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5820 | * This color is used as background color of the confirm credentials screen for that user. |
| 5821 | * |
| 5822 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5823 | * @return The 32bit representation of the color to be used. |
| 5824 | */ |
| 5825 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 5826 | try { |
| 5827 | return mService.getOrganizationColor(admin); |
| 5828 | } catch (RemoteException re) { |
| 5829 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5830 | return 0; |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | /** |
| 5835 | * @hide |
| 5836 | * Retrieve the customization color for a given user. |
| 5837 | * |
| 5838 | * @param userHandle The user id of the user we're interested in. |
| 5839 | * @return The 32bit representation of the color to be used. |
| 5840 | */ |
| 5841 | public int getOrganizationColorForUser(int userHandle) { |
| 5842 | try { |
| 5843 | return mService.getOrganizationColorForUser(userHandle); |
| 5844 | } catch (RemoteException re) { |
| 5845 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5846 | return 0; |
| 5847 | } |
| 5848 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5849 | |
| 5850 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5851 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 5852 | * management. |
| 5853 | * |
| 5854 | * <p>If the organization name needs to be localized, it is the responsibility of the |
| 5855 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5856 | * and set a new version of this string accordingly. |
| 5857 | * |
| 5858 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5859 | * @param title The organization name or {@code null} to clear a previously set name. |
| 5860 | */ |
| 5861 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 5862 | try { |
| 5863 | mService.setOrganizationName(admin, title); |
| 5864 | } catch (RemoteException re) { |
| 5865 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5866 | } |
| 5867 | } |
| 5868 | |
| 5869 | /** |
| 5870 | * Called by a profile owner of a managed profile to retrieve the name of the organization |
| 5871 | * under management. |
| 5872 | * |
| 5873 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5874 | * @return The organization name or {@code null} if none is set. |
| 5875 | */ |
| 5876 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 5877 | try { |
| 5878 | return mService.getOrganizationName(admin); |
| 5879 | } catch (RemoteException re) { |
| 5880 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5881 | return null; |
| 5882 | } |
| 5883 | } |
| 5884 | |
| 5885 | /** |
| 5886 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 5887 | * |
| 5888 | * @param userHandle The user id of the user we're interested in. |
| 5889 | * @return The organization name or {@code null} if none is set. |
| 5890 | * |
| 5891 | * @hide |
| 5892 | */ |
| 5893 | public String getOrganizationNameForUser(int userHandle) { |
| 5894 | try { |
| 5895 | return mService.getOrganizationNameForUser(userHandle); |
| 5896 | } catch (RemoteException re) { |
| 5897 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5898 | return null; |
| 5899 | } |
| 5900 | } |
| 5901 | |
| 5902 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5903 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 5904 | * return {@link #STATE_USER_UNMANAGED} |
| 5905 | * @hide |
| 5906 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 5907 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5908 | @UserProvisioningState |
| 5909 | public int getUserProvisioningState() { |
| 5910 | if (mService != null) { |
| 5911 | try { |
| 5912 | return mService.getUserProvisioningState(); |
| 5913 | } catch (RemoteException e) { |
| 5914 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5915 | } |
| 5916 | } |
| 5917 | return STATE_USER_UNMANAGED; |
| 5918 | } |
| 5919 | |
| 5920 | /** |
| 5921 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 5922 | * |
| 5923 | * @param state to store |
| 5924 | * @param userHandle for user |
| 5925 | * @hide |
| 5926 | */ |
| 5927 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 5928 | if (mService != null) { |
| 5929 | try { |
| 5930 | mService.setUserProvisioningState(state, userHandle); |
| 5931 | } catch (RemoteException e) { |
| 5932 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5933 | } |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5938 | * @hide |
| 5939 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 5940 | * affiliated if it is managed by the same entity as the device. |
| 5941 | * |
| 5942 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 5943 | * user/profile is considered affiliated if the following conditions are both met: |
| 5944 | * <ul> |
| 5945 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 5946 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 5947 | * and a profile owner intersect, they must have come from the same source, which means that |
| 5948 | * the device owner and profile owner are controlled by the same entity.</li> |
| 5949 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 5950 | * </ul> |
| 5951 | * |
| 5952 | * @param admin Which profile or device owner this request is associated with. |
| 5953 | * @param ids A set of opaque affiliation ids. |
| 5954 | */ |
| 5955 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 5956 | try { |
| 5957 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 5958 | } catch (RemoteException e) { |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 5959 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5960 | } |
| 5961 | } |
| 5962 | |
| 5963 | /** |
| 5964 | * @hide |
| 5965 | * Returns whether this user/profile is affiliated with the device. See |
| 5966 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 5967 | * |
| 5968 | * @return whether this user/profile is affiliated with the device. |
| 5969 | */ |
| 5970 | public boolean isAffiliatedUser() { |
| 5971 | try { |
| 5972 | return mService != null && mService.isAffiliatedUser(); |
| 5973 | } catch (RemoteException e) { |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 5974 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5975 | return false; |
| 5976 | } |
| 5977 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 5978 | |
| 5979 | /** |
| 5980 | * @hide |
| 5981 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 5982 | * to be started |
| 5983 | * @param packageName the package to check for |
| 5984 | * @return whether the uninstall intent for {@code packageName} is pending |
| 5985 | */ |
| 5986 | public boolean isUninstallInQueue(String packageName) { |
| 5987 | try { |
| 5988 | return mService.isUninstallInQueue(packageName); |
| 5989 | } catch (RemoteException re) { |
| 5990 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5991 | return false; |
| 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | /** |
| 5996 | * @hide |
| 5997 | * @param packageName the package containing active DAs to be uninstalled |
| 5998 | */ |
| 5999 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 6000 | try { |
| 6001 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 6002 | } catch (RemoteException re) { |
| 6003 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 6004 | } |
| 6005 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 6006 | } |