Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 22 | import android.annotation.SdkConstant; |
| 23 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 24 | import android.annotation.SystemApi; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 25 | import android.app.Activity; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 26 | import android.auditing.SecurityLog; |
| 27 | import android.auditing.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 30 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 31 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
| 33 | import android.content.pm.PackageManager; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 34 | import android.content.pm.ParceledListSlice; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 35 | import android.content.pm.ResolveInfo; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 36 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 38 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 39 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 40 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 41 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 42 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 43 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 44 | import android.os.RemoteException; |
| 45 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 46 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 47 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 48 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 49 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 50 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 51 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 52 | import android.util.Log; |
| 53 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 54 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 55 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 56 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 57 | import org.xmlpull.v1.XmlPullParserException; |
| 58 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 59 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 60 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 61 | import java.lang.annotation.Retention; |
| 62 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 63 | import java.net.InetSocketAddress; |
| 64 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 65 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 66 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 67 | import java.security.PrivateKey; |
| 68 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 69 | import java.security.cert.CertificateException; |
| 70 | import java.security.cert.CertificateFactory; |
| 71 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 72 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 73 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 74 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 75 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 76 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 77 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 80 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 81 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 82 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally, |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 83 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 84 | * accessible to all device administrators unless the documentation for that method specifies that |
| 85 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 86 | * |
| 87 | * <div class="special reference"> |
| 88 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 89 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 90 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 91 | * developer guide. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 92 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 93 | */ |
| 94 | public class DevicePolicyManager { |
| 95 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 96 | |
| 97 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 99 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 100 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 101 | private static final String REMOTE_EXCEPTION_MESSAGE = |
| 102 | "Failed to talk with device policy manager service"; |
| 103 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 104 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 105 | this(context, |
| 106 | IDevicePolicyManager.Stub.asInterface( |
| 107 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 108 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 111 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 112 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 113 | protected DevicePolicyManager( |
| 114 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 115 | mContext = context; |
| 116 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 117 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** @hide */ |
| 121 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 122 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 123 | return me.mService != null ? me : null; |
| 124 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 125 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 126 | /** @hide test will override it. */ |
| 127 | @VisibleForTesting |
| 128 | protected int myUserId() { |
| 129 | return UserHandle.myUserId(); |
| 130 | } |
| 131 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 132 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 133 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 134 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 135 | * <p>A managed profile allows data separation for example for the usage of a |
| 136 | * device as a personal and corporate device. The user which provisioning is started from and |
| 137 | * the managed profile share a launcher. |
| 138 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 139 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 140 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 141 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 142 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 143 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 144 | * {@link #isProvisioningAllowed(String)}. |
| 145 | * |
| 146 | * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 147 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 148 | * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 149 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 150 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 151 | * |
| 152 | * <p> The intent may also contain the following extras: |
| 153 | * <ul> |
| 154 | * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li> |
| 155 | * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li> |
| 156 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 157 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 158 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 159 | * in the provisioning intent. The |
| 160 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 161 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 162 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 163 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 164 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 165 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 166 | * |
| 167 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 168 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 169 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 170 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 171 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 172 | */ |
| 173 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 174 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 175 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 176 | |
| 177 | /** |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 178 | * @hide |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 179 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 180 | * |
| 181 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 182 | * Provisioning configures the user as managed user and sets the MDM as the profile |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 183 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 184 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 185 | * allowed. |
| 186 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 187 | * <p>This intent should contain the extra |
| 188 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 189 | * |
| 190 | * <p> If provisioning fails, the device returns to its previous state. |
| 191 | * |
| 192 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 193 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 194 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 195 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 196 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 197 | */ |
| 198 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 199 | public static final String ACTION_PROVISION_MANAGED_USER |
| 200 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 201 | |
| 202 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 203 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 204 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 205 | * |
| 206 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 207 | * A device owner has full control over the device. The device owner can not be modified by the |
| 208 | * user. |
| 209 | * |
| 210 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 211 | * employee or client. |
| 212 | * |
| 213 | * <p> An intent with this action can be sent only on an unprovisioned device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 214 | * It is possible to check if provisioning is allowed or not by querying the method |
| 215 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 216 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 217 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 218 | * <ul> |
| 219 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 220 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 221 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 222 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 223 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 224 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 225 | * </ul> |
| 226 | * |
| 227 | * <p> When device owner provisioning has completed, an intent of the type |
| 228 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 229 | * device owner. |
| 230 | * |
| 231 | * <p> If provisioning fails, the device is factory reset. |
| 232 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 233 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 234 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 235 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 236 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 237 | */ |
| 238 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 239 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 240 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 241 | |
| 242 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 243 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 244 | * |
| 245 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 246 | * the device. A device owner has full control over the device. The device owner can not be |
| 247 | * modified by the user and the only way of resetting the device is via factory reset. |
| 248 | * |
| 249 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 250 | * employee or client. |
| 251 | * |
| 252 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 253 | * |
| 254 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 255 | * by a privileged app with the permission |
| 256 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 257 | * |
| 258 | * <p>The provisioning intent contains the following properties: |
| 259 | * <ul> |
| 260 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 261 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 262 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 276 | * |
| 277 | * @hide |
| 278 | */ |
| 279 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 280 | @SystemApi |
| 281 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 282 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 283 | |
| 284 | /** |
| 285 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 286 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 287 | * |
| 288 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 289 | * management state that is distinct from that reached by |
| 290 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 291 | * user, and only has control over device-wide policies, not individual users and their data. |
| 292 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 293 | * this form of device management. |
| 294 | * |
| 295 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 296 | * A device owner has full control over the device. The device owner can not be modified by the |
| 297 | * user. |
| 298 | * |
| 299 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 300 | * employee or client. |
| 301 | * |
| 302 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 303 | * It is possible to check if provisioning is allowed or not by querying the method |
| 304 | * {@link #isProvisioningAllowed(String)}. |
| 305 | * |
| 306 | * <p>The intent contains the following extras: |
| 307 | * <ul> |
| 308 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 309 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 310 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 312 | * </ul> |
| 313 | * |
| 314 | * <p> When device owner provisioning has completed, an intent of the type |
| 315 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 316 | * device owner. |
| 317 | * |
| 318 | * <p> If provisioning fails, the device is factory reset. |
| 319 | * |
| 320 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 321 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 322 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 323 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 324 | * |
| 325 | * @hide |
| 326 | */ |
| 327 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 328 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 329 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 330 | |
| 331 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 332 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 333 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 334 | * <ul> |
| 335 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 336 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 337 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 338 | * </ul> |
| 339 | * |
| 340 | * @hide |
| 341 | */ |
| 342 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 343 | public static final String ACTION_PROVISION_FINALIZATION |
| 344 | = "android.app.action.PROVISION_FINALIZATION"; |
| 345 | |
| 346 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 347 | * 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] | 348 | * allows a mobile device management application or NFC programmer application which starts |
| 349 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 350 | * <p> |
| 351 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 352 | * sends the intent to pass data to itself on the newly created profile. |
| 353 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 354 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 355 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 356 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 357 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 358 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 359 | * management application after provisioning. |
| 360 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 361 | * <p> |
| 362 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 363 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 364 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 365 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 366 | */ |
| 367 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 368 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 369 | |
| 370 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 371 | * A String extra holding the package name of the mobile device management application that |
| 372 | * will be set as the profile owner or device owner. |
| 373 | * |
| 374 | * <p>If an application starts provisioning directly via an intent with action |
| 375 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 376 | * application that started provisioning. The package will be set as profile owner in that case. |
| 377 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 378 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 379 | * 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] | 380 | * |
| 381 | * <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] | 382 | * 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] | 383 | |
| 384 | * @see DeviceAdminReceiver |
| 385 | * @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] | 386 | * supported, but only if there is only one device admin receiver in the package that requires |
| 387 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 388 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 389 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 390 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 391 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 392 | |
| 393 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 394 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 395 | * application that will be set as the profile owner or device owner and active admin. |
| 396 | * |
| 397 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 398 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 399 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 400 | * 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] | 401 | * |
| 402 | * <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] | 403 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 404 | * message containing an NFC record with MIME type |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 405 | * {@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] | 406 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 407 | * |
| 408 | * @see DeviceAdminReceiver |
| 409 | */ |
| 410 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 411 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 412 | |
| 413 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 414 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 415 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 416 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 417 | * |
| 418 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 419 | */ |
| 420 | |
| 421 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 422 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 423 | |
| 424 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 425 | * A String extra that, holds the email address of the account which a managed profile is |
| 426 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 427 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 428 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 429 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 430 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 431 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 432 | * contains this extra, it is forwarded in the |
| 433 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 434 | * device management application that was set as the profile owner during provisioning. |
| 435 | * 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] | 436 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 437 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 438 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 439 | |
| 440 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 441 | * A integer extra indicating the predominant color to show during the provisioning. |
| 442 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 443 | * |
| 444 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 445 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 446 | */ |
| 447 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 448 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 449 | |
| 450 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 451 | * 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] | 452 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 453 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 454 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 455 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 456 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 457 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 458 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 459 | |
| 460 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 461 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 462 | * will be set to. |
| 463 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 464 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 465 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 466 | */ |
| 467 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 468 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 469 | |
| 470 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 471 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 472 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 473 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 474 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 475 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 476 | */ |
| 477 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 478 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 479 | |
| 480 | /** |
| 481 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 482 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 483 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 484 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 485 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 486 | */ |
| 487 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 488 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 489 | |
| 490 | /** |
| 491 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 492 | * owner provisioning for downloading the mobile device management application. |
| 493 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 494 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 495 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 496 | */ |
| 497 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 498 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 499 | |
| 500 | /** |
| 501 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 502 | * is hidden or not. |
| 503 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 504 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 505 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 506 | */ |
| 507 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 508 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 509 | |
| 510 | /** |
| 511 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 512 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 513 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 514 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 515 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 516 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 517 | */ |
| 518 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 519 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 520 | |
| 521 | /** |
| 522 | * A String extra holding the password of the wifi network in |
| 523 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 524 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 525 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 526 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 527 | */ |
| 528 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 529 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 530 | |
| 531 | /** |
| 532 | * A String extra holding the proxy host for the wifi network in |
| 533 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 534 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 535 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 536 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 537 | */ |
| 538 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 539 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 540 | |
| 541 | /** |
| 542 | * An int extra holding the proxy port for the wifi network in |
| 543 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 544 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 545 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 546 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 547 | */ |
| 548 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 549 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 550 | |
| 551 | /** |
| 552 | * A String extra holding the proxy bypass for the wifi network in |
| 553 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 554 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 555 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 556 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 557 | */ |
| 558 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 559 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 560 | |
| 561 | /** |
| 562 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 563 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 564 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 565 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 566 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 567 | */ |
| 568 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 569 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 570 | |
| 571 | /** |
| 572 | * A String extra holding a url that specifies the download location of the device admin |
| 573 | * package. When not provided it is assumed that the device admin package is already installed. |
| 574 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 575 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 576 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 577 | */ |
| 578 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 579 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 580 | |
| 581 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 582 | * An int extra holding a minimum required version code for the device admin package. If the |
| 583 | * device admin is already installed on the device, it will only be re-downloaded from |
| 584 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 585 | * installed package is less than this version code. |
| 586 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 587 | * <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] | 588 | * provisioning via an NFC bump. |
| 589 | */ |
| 590 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 591 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 592 | |
| 593 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 594 | * A String extra holding a http cookie header which should be used in the http request to the |
| 595 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 596 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 597 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 598 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 599 | */ |
| 600 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 601 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 602 | |
| 603 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 604 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 605 | * the file at download location specified in |
| 606 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 607 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 608 | * <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] | 609 | * present. The provided checksum should match the checksum of the file at the download |
| 610 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 611 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 613 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 614 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 615 | * |
| 616 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 617 | * 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] | 618 | * 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] | 619 | * 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] | 620 | */ |
| 621 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 622 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 623 | |
| 624 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 625 | * 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] | 626 | * android package archive at the download location specified in {@link |
| 627 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 628 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 629 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 630 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 631 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 632 | * |
| 633 | * <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] | 634 | * 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] | 635 | * the download location. If the checksum does not match an error will be shown to the user and |
| 636 | * the user will be asked to factory reset the device. |
| 637 | * |
| 638 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 639 | * provisioning via an NFC bump. |
| 640 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 641 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 642 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 643 | |
| 644 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 645 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 646 | * has completed successfully. |
| 647 | * |
| 648 | * <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] | 649 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 650 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 651 | * <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] | 652 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 653 | */ |
| 654 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 655 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 656 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 657 | |
| 658 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 659 | * 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] | 660 | * provisioning. |
| 661 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 662 | * <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] | 663 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 664 | */ |
| 665 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 666 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 667 | |
| 668 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 669 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 670 | * provisioning. If this extra is not passed, a default image will be shown. |
| 671 | * <h5>The following URI schemes are accepted:</h5> |
| 672 | * <ul> |
| 673 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 674 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 675 | * </ul> |
| 676 | * |
| 677 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 678 | * pixed density for the device. |
| 679 | * |
| 680 | * <p> If a content: URI is passed, the intent should have the flag |
| 681 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 682 | * {@link android.content.ClipData} of the intent too. |
| 683 | * |
| 684 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 685 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 686 | */ |
| 687 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 688 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 689 | |
| 690 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 691 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 692 | * during setup-wizard. |
| 693 | * |
| 694 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 695 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 696 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 697 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 698 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 699 | * |
| 700 | * @hide |
| 701 | */ |
| 702 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 703 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 704 | |
| 705 | /** |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 706 | * This MIME type is used for starting the Device Owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 707 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 708 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 709 | * A device owner has full control over the device. The device owner can not be modified by the |
| 710 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 711 | * reset. |
| 712 | * |
| 713 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 714 | * employee or client. |
| 715 | * |
| 716 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 717 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 718 | * <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] | 719 | * contains the following properties: |
| 720 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 721 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 722 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 723 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 724 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 725 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 726 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 727 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 728 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 729 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 730 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 731 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 732 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 733 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 734 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 735 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 736 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 737 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 738 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 739 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 740 | * 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] | 741 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 742 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 743 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 744 | */ |
| 745 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 746 | = "application/com.android.managedprovisioning"; |
| 747 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 748 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 749 | * Activity action: ask the user to add a new device administrator to the system. |
| 750 | * The desired policy is the ComponentName of the policy in the |
| 751 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 752 | * bring the user through adding the device administrator to the system (or |
| 753 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 754 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 755 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 756 | * field to provide the user with additional explanation (in addition |
| 757 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 758 | * |
| 759 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 760 | * user intervention). However, if your administrator has been updated and is requesting |
| 761 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 762 | * 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] | 763 | */ |
| 764 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 765 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 766 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 767 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 768 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 769 | * @hide |
| 770 | * 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] | 771 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 772 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 773 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 774 | * 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] | 775 | * to remotely control restrictions on the user. |
| 776 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 777 | * <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] | 778 | * result of whether or not the user approved the action. If approved, the result will |
| 779 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 780 | * as a profile owner. |
| 781 | * |
| 782 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 783 | * field to provide the user with additional explanation (in addition |
| 784 | * to your component's description) about what is being added. |
| 785 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 786 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 787 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 788 | */ |
| 789 | @SystemApi |
| 790 | public static final String ACTION_SET_PROFILE_OWNER |
| 791 | = "android.app.action.SET_PROFILE_OWNER"; |
| 792 | |
| 793 | /** |
| 794 | * @hide |
| 795 | * Name of the profile owner admin that controls the user. |
| 796 | */ |
| 797 | @SystemApi |
| 798 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 799 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 800 | |
| 801 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 802 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 803 | * 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] | 804 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 805 | * @hide |
| 806 | */ |
| 807 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 808 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 809 | |
| 810 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 811 | * Broadcast action: sent when the device owner is set or changed. |
| 812 | * |
| 813 | * This broadcast is sent only to the primary user. |
| 814 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 815 | */ |
| 816 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 817 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 818 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 819 | |
| 820 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 821 | * The ComponentName of the administrator component. |
| 822 | * |
| 823 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 824 | */ |
| 825 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 826 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 827 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 828 | * An optional CharSequence providing additional explanation for why the |
| 829 | * admin is being added. |
| 830 | * |
| 831 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 832 | */ |
| 833 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 834 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 835 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 836 | * Activity action: have the user enter a new password. This activity should |
| 837 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 838 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 839 | * enter a new password that meets the current requirements. You can use |
| 840 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 841 | * have the user select a new password in order to meet the current |
| 842 | * constraints. Upon being resumed from this activity, you can check the new |
| 843 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 844 | * |
| 845 | * If the intent is launched from within a managed profile with a profile |
| 846 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 847 | * this will trigger entering a new password for the parent of the profile. |
| 848 | * For all other cases it will trigger entering a new password for the user |
| 849 | * or profile it is launched from. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 850 | */ |
| 851 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 852 | public static final String ACTION_SET_NEW_PASSWORD |
| 853 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 854 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 855 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 856 | * Activity action: have the user enter a new password for the parent profile. |
| 857 | * If the intent is launched from within a managed profile, this will trigger |
| 858 | * entering a new password for the parent of the profile. In all other cases |
| 859 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 860 | */ |
| 861 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 862 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 863 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 864 | |
| 865 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 866 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 867 | * the parent profile to access intents sent from the managed profile. |
| 868 | * That is, when an app in the managed profile calls |
| 869 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 870 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 871 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 872 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 873 | |
| 874 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 875 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 876 | * the managed profile to access intents sent from the parent profile. |
| 877 | * That is, when an app in the parent profile calls |
| 878 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 879 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 880 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 881 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 882 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 883 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 884 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 885 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 886 | */ |
| 887 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 888 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 889 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 890 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 891 | /** |
| 892 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 893 | * Already granted or denied permissions are not affected by this. |
| 894 | */ |
| 895 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 896 | |
| 897 | /** |
| 898 | * Permission policy to always grant new permission requests for runtime permissions. |
| 899 | * Already granted or denied permissions are not affected by this. |
| 900 | */ |
| 901 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 902 | |
| 903 | /** |
| 904 | * Permission policy to always deny new permission requests for runtime permissions. |
| 905 | * Already granted or denied permissions are not affected by this. |
| 906 | */ |
| 907 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 908 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 909 | /** |
| 910 | * Runtime permission state: The user can manage the permission |
| 911 | * through the UI. |
| 912 | */ |
| 913 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 914 | |
| 915 | /** |
| 916 | * Runtime permission state: The permission is granted to the app |
| 917 | * and the user cannot manage the permission through the UI. |
| 918 | */ |
| 919 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 920 | |
| 921 | /** |
| 922 | * Runtime permission state: The permission is denied to the app |
| 923 | * and the user cannot manage the permission through the UI. |
| 924 | */ |
| 925 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 926 | |
| 927 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 928 | * No management for current user in-effect. This is the default. |
| 929 | * @hide |
| 930 | */ |
| 931 | public static final int STATE_USER_UNMANAGED = 0; |
| 932 | |
| 933 | /** |
| 934 | * Management partially setup, user setup needs to be completed. |
| 935 | * @hide |
| 936 | */ |
| 937 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 938 | |
| 939 | /** |
| 940 | * Management partially setup, user setup completed. |
| 941 | * @hide |
| 942 | */ |
| 943 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 944 | |
| 945 | /** |
| 946 | * Management setup and active on current user. |
| 947 | * @hide |
| 948 | */ |
| 949 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 950 | |
| 951 | /** |
| 952 | * Management partially setup on a managed profile. |
| 953 | * @hide |
| 954 | */ |
| 955 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 956 | |
| 957 | /** |
| 958 | * @hide |
| 959 | */ |
| 960 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 961 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 962 | @Retention(RetentionPolicy.SOURCE) |
| 963 | public @interface UserProvisioningState {} |
| 964 | |
| 965 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 966 | * Return true if the given administrator component is currently |
| 967 | * active (enabled) in the system. |
| 968 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 969 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 970 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /** |
| 974 | * @see #isAdminActive(ComponentName) |
| 975 | * @hide |
| 976 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 977 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 978 | if (mService != null) { |
| 979 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 980 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 981 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 982 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | return false; |
| 986 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 987 | /** |
| 988 | * Return true if the given administrator component is currently being removed |
| 989 | * for the user. |
| 990 | * @hide |
| 991 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 992 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 993 | if (mService != null) { |
| 994 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 995 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 996 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 997 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | return false; |
| 1001 | } |
| 1002 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1003 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1004 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1005 | * Return a list of all currently active device administrators' component |
| 1006 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1007 | * returned. |
| 1008 | */ |
| 1009 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1010 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * @see #getActiveAdmins() |
| 1015 | * @hide |
| 1016 | */ |
| 1017 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1018 | if (mService != null) { |
| 1019 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1020 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1021 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1022 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | return null; |
| 1026 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1027 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1028 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1029 | * Used by package administration code to determine if a package can be stopped |
| 1030 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1031 | * @hide |
| 1032 | */ |
| 1033 | public boolean packageHasActiveAdmins(String packageName) { |
| 1034 | if (mService != null) { |
| 1035 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1036 | return mService.packageHasActiveAdmins(packageName, myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1037 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1038 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | return false; |
| 1042 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1043 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1044 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1045 | * Remove a current administration component. This can only be called |
| 1046 | * by the application that owns the administration component; if you |
| 1047 | * try to remove someone else's component, a security exception will be |
| 1048 | * thrown. |
| 1049 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1050 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1051 | if (mService != null) { |
| 1052 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1053 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1054 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1055 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1056 | } |
| 1057 | } |
| 1058 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1059 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1060 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1061 | * 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] | 1062 | * 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] | 1063 | * but requires additional policies after an upgrade. |
| 1064 | * |
| 1065 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 1066 | * an active administrator, or an exception will be thrown. |
| 1067 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 1068 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1069 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1070 | if (mService != null) { |
| 1071 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1072 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1073 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1074 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | return false; |
| 1078 | } |
| 1079 | |
| 1080 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1081 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1082 | * |
| 1083 | * @hide |
| 1084 | */ |
| 1085 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1086 | if (mService != null) { |
| 1087 | try { |
| 1088 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1089 | } catch (RemoteException e) { |
| 1090 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1091 | } |
| 1092 | } |
| 1093 | return false; |
| 1094 | } |
| 1095 | |
| 1096 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1097 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1098 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1099 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1100 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1101 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1102 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1103 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1104 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1105 | * recognition technology. This implies technologies that can recognize the identity of |
| 1106 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1107 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1108 | */ |
| 1109 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1110 | |
| 1111 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1112 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1113 | * 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] | 1114 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1115 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1116 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1117 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1118 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1119 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1120 | * password containing at least numeric characters. Note that quality |
| 1121 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1122 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1123 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
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 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1126 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1127 | * password containing at least numeric characters with no repeating (4444) |
| 1128 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1129 | * constants are ordered so that higher values are more restrictive. |
| 1130 | */ |
| 1131 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1132 | |
| 1133 | /** |
| 1134 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1135 | * password containing at least alphabetic (or other symbol) characters. |
| 1136 | * Note that quality constants are ordered so that higher values are more |
| 1137 | * restrictive. |
| 1138 | */ |
| 1139 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1140 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1141 | /** |
| 1142 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1143 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1144 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1145 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1146 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1147 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1148 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1149 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1150 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1151 | * password containing at least a letter, a numerical digit and a special |
| 1152 | * symbol, by default. With this password quality, passwords can be |
| 1153 | * restricted to contain various sets of characters, like at least an |
| 1154 | * uppercase letter, etc. These are specified using various methods, |
| 1155 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1156 | * that quality constants are ordered so that higher values are more |
| 1157 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1158 | */ |
| 1159 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1160 | |
| 1161 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1162 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1163 | * modify password. In case this password quality is set, the password is |
| 1164 | * managed by a profile owner. The profile owner can set any password, |
| 1165 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1166 | * that quality constants are ordered so that higher values are more |
| 1167 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1168 | * the highest. |
| 1169 | * @hide |
| 1170 | */ |
| 1171 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1172 | |
| 1173 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1174 | * Called by an application that is administering the device to set the |
| 1175 | * password restrictions it is imposing. After setting this, the user |
| 1176 | * will not be able to enter a new password that is not at least as |
| 1177 | * restrictive as what has been set. Note that the current password |
| 1178 | * will remain until the user has set a new one, so the change does not |
| 1179 | * take place immediately. To prompt the user for a new password, use |
| 1180 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1181 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1182 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 1183 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1184 | * the user's preference, and any other considerations) is the one that |
| 1185 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1186 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1187 | * <p>The calling device admin must have requested |
| 1188 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1189 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1190 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1191 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1192 | * @param quality The new desired quality. One of |
| 1193 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1194 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1195 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1196 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1197 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1198 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1199 | if (mService != null) { |
| 1200 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1201 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1202 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1203 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1207 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1208 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1209 | * Retrieve the current minimum password quality for all admins of this user |
| 1210 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1211 | * @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] | 1212 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1213 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1214 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1215 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1219 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1220 | if (mService != null) { |
| 1221 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1222 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1223 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1224 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1225 | } |
| 1226 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1227 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1228 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1229 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1230 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1231 | * Called by an application that is administering the device to set the |
| 1232 | * minimum allowed password length. After setting this, the user |
| 1233 | * will not be able to enter a new password that is not at least as |
| 1234 | * restrictive as what has been set. Note that the current password |
| 1235 | * will remain until the user has set a new one, so the change does not |
| 1236 | * take place immediately. To prompt the user for a new password, use |
| 1237 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1238 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1239 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1240 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1241 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1242 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1243 | * <p>The calling device admin must have requested |
| 1244 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1245 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1246 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1247 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1248 | * @param length The new desired minimum password length. A value of 0 |
| 1249 | * means there is no restriction. |
| 1250 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1251 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1252 | if (mService != null) { |
| 1253 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1254 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1255 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1256 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1260 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1261 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1262 | * Retrieve the current minimum password length for all admins of this |
| 1263 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1264 | * @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] | 1265 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1266 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1267 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1268 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1272 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1273 | if (mService != null) { |
| 1274 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1275 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1276 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1277 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1278 | } |
| 1279 | } |
| 1280 | return 0; |
| 1281 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1282 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1283 | /** |
| 1284 | * Called by an application that is administering the device to set the |
| 1285 | * minimum number of upper case letters required in the password. After |
| 1286 | * setting this, the user will not be able to enter a new password that is |
| 1287 | * not at least as restrictive as what has been set. Note that the current |
| 1288 | * password will remain until the user has set a new one, so the change does |
| 1289 | * not take place immediately. To prompt the user for a new password, use |
| 1290 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1291 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1292 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1293 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1294 | * <p> |
| 1295 | * The calling device admin must have requested |
| 1296 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1297 | * this method; if it has not, a security exception will be thrown. |
| 1298 | * |
| 1299 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1300 | * with. |
| 1301 | * @param length The new desired minimum number of upper case letters |
| 1302 | * required in the password. A value of 0 means there is no |
| 1303 | * restriction. |
| 1304 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1305 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1306 | if (mService != null) { |
| 1307 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1308 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1309 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1310 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | /** |
| 1316 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1317 | * password for all admins of this user and its profiles or a particular one. |
| 1318 | * This is the same value as set by |
| 1319 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1320 | * and only applies when the password quality is |
| 1321 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1322 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1323 | * @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] | 1324 | * aggregate all admins. |
| 1325 | * @return The minimum number of upper case letters required in the |
| 1326 | * password. |
| 1327 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1328 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1329 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1333 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1334 | if (mService != null) { |
| 1335 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1336 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1337 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1338 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * Called by an application that is administering the device to set the |
| 1346 | * minimum number of lower case letters required in the password. After |
| 1347 | * setting this, the user will not be able to enter a new password that is |
| 1348 | * not at least as restrictive as what has been set. Note that the current |
| 1349 | * password will remain until the user has set a new one, so the change does |
| 1350 | * not take place immediately. To prompt the user for a new password, use |
| 1351 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1352 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1353 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1354 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1355 | * <p> |
| 1356 | * The calling device admin must have requested |
| 1357 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1358 | * this method; if it has not, a security exception will be thrown. |
| 1359 | * |
| 1360 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1361 | * with. |
| 1362 | * @param length The new desired minimum number of lower case letters |
| 1363 | * required in the password. A value of 0 means there is no |
| 1364 | * restriction. |
| 1365 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1366 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1367 | if (mService != null) { |
| 1368 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1369 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1370 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1371 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1378 | * password for all admins of this user and its profiles or a particular one. |
| 1379 | * This is the same value as set by |
| 1380 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1381 | * and only applies when the password quality is |
| 1382 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1383 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1384 | * @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] | 1385 | * aggregate all admins. |
| 1386 | * @return The minimum number of lower case letters required in the |
| 1387 | * password. |
| 1388 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1389 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1390 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1394 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1395 | if (mService != null) { |
| 1396 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1397 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1398 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1399 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | return 0; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * Called by an application that is administering the device to set the |
| 1407 | * minimum number of letters required in the password. After setting this, |
| 1408 | * the user will not be able to enter a new password that is not at least as |
| 1409 | * restrictive as what has been set. Note that the current password will |
| 1410 | * remain until the user has set a new one, so the change does not take |
| 1411 | * place immediately. To prompt the user for a new password, use |
| 1412 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1413 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1414 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1415 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1416 | * <p> |
| 1417 | * The calling device admin must have requested |
| 1418 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1419 | * this method; if it has not, a security exception will be thrown. |
| 1420 | * |
| 1421 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1422 | * with. |
| 1423 | * @param length The new desired minimum number of letters required in the |
| 1424 | * password. A value of 0 means there is no restriction. |
| 1425 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1426 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1427 | if (mService != null) { |
| 1428 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1429 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1430 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1431 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | /** |
| 1437 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1438 | * admins or a particular one. This is the same value as |
| 1439 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 1440 | * and only applies when the password quality is |
| 1441 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1442 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1443 | * @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] | 1444 | * aggregate all admins. |
| 1445 | * @return The minimum number of letters required in the password. |
| 1446 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1447 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1448 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1452 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1453 | if (mService != null) { |
| 1454 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1455 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1456 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1457 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
| 1463 | /** |
| 1464 | * Called by an application that is administering the device to set the |
| 1465 | * minimum number of numerical digits required in the password. After |
| 1466 | * setting this, the user will not be able to enter a new password that is |
| 1467 | * not at least as restrictive as what has been set. Note that the current |
| 1468 | * password will remain until the user has set a new one, so the change does |
| 1469 | * not take place immediately. To prompt the user for a new password, use |
| 1470 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1471 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1472 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1473 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1474 | * <p> |
| 1475 | * The calling device admin must have requested |
| 1476 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1477 | * this method; if it has not, a security exception will be thrown. |
| 1478 | * |
| 1479 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1480 | * with. |
| 1481 | * @param length The new desired minimum number of numerical digits required |
| 1482 | * in the password. A value of 0 means there is no restriction. |
| 1483 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1484 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1485 | if (mService != null) { |
| 1486 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1487 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1488 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1489 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1490 | } |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | /** |
| 1495 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1496 | * for all admins of this user and its profiles or a particular one. |
| 1497 | * This is the same value as set by |
| 1498 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1499 | * and only applies when the password quality is |
| 1500 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1501 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1502 | * @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] | 1503 | * aggregate all admins. |
| 1504 | * @return The minimum number of numerical digits required in the password. |
| 1505 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1506 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1507 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1511 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1512 | if (mService != null) { |
| 1513 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1514 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1515 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1516 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
| 1522 | /** |
| 1523 | * Called by an application that is administering the device to set the |
| 1524 | * minimum number of symbols required in the password. After setting this, |
| 1525 | * the user will not be able to enter a new password that is not at least as |
| 1526 | * restrictive as what has been set. Note that the current password will |
| 1527 | * remain until the user has set a new one, so the change does not take |
| 1528 | * place immediately. To prompt the user for a new password, use |
| 1529 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1530 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1531 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1532 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1533 | * <p> |
| 1534 | * The calling device admin must have requested |
| 1535 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1536 | * this method; if it has not, a security exception will be thrown. |
| 1537 | * |
| 1538 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1539 | * with. |
| 1540 | * @param length The new desired minimum number of symbols required in the |
| 1541 | * password. A value of 0 means there is no restriction. |
| 1542 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1543 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1544 | if (mService != null) { |
| 1545 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1546 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1547 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1548 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1549 | } |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | /** |
| 1554 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1555 | * admins or a particular one. This is the same value as |
| 1556 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1557 | * and only applies when the password quality is |
| 1558 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1559 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1560 | * @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] | 1561 | * aggregate all admins. |
| 1562 | * @return The minimum number of symbols required in the password. |
| 1563 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1564 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1565 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1569 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1570 | if (mService != null) { |
| 1571 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1572 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1573 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1574 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1580 | /** |
| 1581 | * Called by an application that is administering the device to set the |
| 1582 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1583 | * required in the password. After setting this, the user will not be able |
| 1584 | * to enter a new password that is not at least as restrictive as what has |
| 1585 | * been set. Note that the current password will remain until the user has |
| 1586 | * set a new one, so the change does not take place immediately. To prompt |
| 1587 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1588 | * setting this value. This constraint is only imposed if the administrator |
| 1589 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1590 | * {@link #setPasswordQuality}. The default value is 0. |
| 1591 | * <p> |
| 1592 | * The calling device admin must have requested |
| 1593 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1594 | * this method; if it has not, a security exception will be thrown. |
| 1595 | * |
| 1596 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1597 | * with. |
| 1598 | * @param length The new desired minimum number of letters required in the |
| 1599 | * password. A value of 0 means there is no restriction. |
| 1600 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1601 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1602 | if (mService != null) { |
| 1603 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1604 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -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 | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | /** |
| 1612 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1613 | * password for all admins of this user and its profiles or a particular one. |
| 1614 | * This is the same value as set by |
| 1615 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1616 | * and only applies when the password quality is |
| 1617 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1618 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1619 | * @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] | 1620 | * aggregate all admins. |
| 1621 | * @return The minimum number of letters required in the password. |
| 1622 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1623 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1624 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1628 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1629 | if (mService != null) { |
| 1630 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1631 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1632 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1633 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | return 0; |
| 1637 | } |
| 1638 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1639 | /** |
| 1640 | * Called by an application that is administering the device to set the length |
| 1641 | * of the password history. After setting this, the user will not be able to |
| 1642 | * enter a new password that is the same as any password in the history. Note |
| 1643 | * that the current password will remain until the user has set a new one, so |
| 1644 | * the change does not take place immediately. To prompt the user for a new |
| 1645 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1646 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1647 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1648 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1649 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1650 | * |
| 1651 | * <p> |
| 1652 | * The calling device admin must have requested |
| 1653 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1654 | * method; if it has not, a security exception will be thrown. |
| 1655 | * |
| 1656 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1657 | * with. |
| 1658 | * @param length The new desired length of password history. A value of 0 |
| 1659 | * means there is no restriction. |
| 1660 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1661 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1662 | if (mService != null) { |
| 1663 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1664 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1665 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1666 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1672 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1673 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1674 | * the device password (for all admins). |
| 1675 | * |
| 1676 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1677 | * For example, to have the password expire 5 days from now, timeout would be |
| 1678 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1679 | * |
| 1680 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1681 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1682 | * <p>The calling device admin must have requested |
| 1683 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1684 | * method; if it has not, a security exception will be thrown. |
| 1685 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1686 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1687 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1688 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1689 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1690 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1691 | * means there is no restriction (unlimited). |
| 1692 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1693 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1694 | if (mService != null) { |
| 1695 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1696 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1697 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1698 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1704 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1705 | * recurring expiration timeout provided in the call to |
| 1706 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1707 | * aggregate of all policy administrators if {@code admin} is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1708 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1709 | * @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] | 1710 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1711 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1712 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1713 | if (mService != null) { |
| 1714 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1715 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1716 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1717 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1718 | } |
| 1719 | } |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
| 1723 | /** |
| 1724 | * Get the current password expiration time for the given admin or an aggregate of |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1725 | * all admins of this user and its profiles if admin is null. If the password is |
| 1726 | * expired, this will return the time since the password expired as a negative number. |
| 1727 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1728 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1729 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1730 | * @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] | 1731 | * @return The password expiration time, in ms. |
| 1732 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1733 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1734 | if (mService != null) { |
| 1735 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1736 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1737 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1738 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1745 | * Retrieve the current password history length for all admins of this |
| 1746 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1747 | * @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] | 1748 | * all admins. |
| 1749 | * @return The length of the password history |
| 1750 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1751 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1752 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1756 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1757 | if (mService != null) { |
| 1758 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1759 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1760 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1761 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1762 | } |
| 1763 | } |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1767 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1768 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1769 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1770 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1771 | * @return Returns the maximum length that the user can enter. |
| 1772 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1773 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1774 | // Kind-of arbitrary. |
| 1775 | return 16; |
| 1776 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1777 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1778 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1779 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1780 | * to meet the policy requirements (quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1781 | * requested by the admins of this user and its profiles that don't have a separate challenge. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1782 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1783 | * <p>The calling device admin must have requested |
| 1784 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1785 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1786 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1787 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1788 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1789 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1790 | if (mService != null) { |
| 1791 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1792 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1793 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1794 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1795 | } |
| 1796 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1797 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1798 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1799 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1800 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1801 | * Determine whether the current profile password the user has set is sufficient |
| 1802 | * to meet the policy requirements (quality, minimum length) that have been |
| 1803 | * requested by the admins of the parent user and its profiles. |
| 1804 | * |
| 1805 | * @param userHandle the userId of the profile to check the password for. |
| 1806 | * @return Returns true if the password would meet the current requirements, else false. |
| 1807 | * @hide |
| 1808 | */ |
| 1809 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 1810 | if (mService != null) { |
| 1811 | try { |
| 1812 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 1813 | } catch (RemoteException e) { |
| 1814 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1815 | } |
| 1816 | } |
| 1817 | return false; |
| 1818 | } |
| 1819 | |
| 1820 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1821 | * Retrieve the number of times the user has failed at entering a |
| 1822 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1823 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1824 | * <p>The calling device admin must have requested |
| 1825 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1826 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1827 | */ |
| 1828 | public int getCurrentFailedPasswordAttempts() { |
| 1829 | if (mService != null) { |
| 1830 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1831 | return mService.getCurrentFailedPasswordAttempts(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1832 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1833 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1834 | } |
| 1835 | } |
| 1836 | return -1; |
| 1837 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1838 | |
| 1839 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1840 | * 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] | 1841 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1842 | * @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] | 1843 | * @hide |
| 1844 | */ |
| 1845 | public boolean getDoNotAskCredentialsOnBoot() { |
| 1846 | if (mService != null) { |
| 1847 | try { |
| 1848 | return mService.getDoNotAskCredentialsOnBoot(); |
| 1849 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1850 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | return false; |
| 1854 | } |
| 1855 | |
| 1856 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1857 | * Setting this to a value greater than zero enables a built-in policy |
| 1858 | * that will perform a device wipe after too many incorrect |
| 1859 | * device-unlock passwords have been entered. This built-in policy combines |
| 1860 | * watching for failed passwords and wiping the device, and requires |
| 1861 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1862 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1863 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1864 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1865 | * application only, erasing or revoking credentials, or reporting the |
| 1866 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1867 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1868 | * instead. Do not use this API, because if the maximum count is reached, |
| 1869 | * the device will be wiped immediately, and your callback will not be invoked. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1870 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1872 | * @param num The number of failed password attempts at which point the |
| 1873 | * device will wipe its data. |
| 1874 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1875 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1876 | if (mService != null) { |
| 1877 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1878 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1879 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1880 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1881 | } |
| 1882 | } |
| 1883 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1884 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1885 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1886 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1887 | * before the device wipes itself, for all admins of this user and its profiles |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1888 | * or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1889 | * @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] | 1890 | * all admins. |
| 1891 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1892 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1893 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1897 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1898 | if (mService != null) { |
| 1899 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1900 | return mService.getMaximumFailedPasswordsForWipe( |
| 1901 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1902 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1903 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1904 | } |
| 1905 | } |
| 1906 | return 0; |
| 1907 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1908 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1909 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1910 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1911 | * for the given user. So for primary user, it might return the primary or |
| 1912 | * a managed profile. For a secondary user, it would be the same as the |
| 1913 | * user passed in. |
| 1914 | * @hide Used only by Keyguard |
| 1915 | */ |
| 1916 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1917 | if (mService != null) { |
| 1918 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1919 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 1920 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1921 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1922 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1923 | } |
| 1924 | } |
| 1925 | return UserHandle.USER_NULL; |
| 1926 | } |
| 1927 | |
| 1928 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1929 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1930 | * the password again until the user has entered it. |
| 1931 | */ |
| 1932 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1933 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1934 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1935 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 1936 | * If the flag is set, the device can be booted without asking for user password. |
| 1937 | * The absence of this flag does not change the current boot requirements. This flag |
| 1938 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 1939 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 1940 | * device to factory defaults. |
| 1941 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1942 | 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] | 1943 | |
| 1944 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1945 | * Force a new device unlock password (the password needed to access the |
| 1946 | * entire device, not for individual accounts) on the user. This takes |
| 1947 | * effect immediately. |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 1948 | * |
| 1949 | * <p>Calling this from a managed profile that shares the password with the owner profile |
| 1950 | * will throw a security exception. |
| 1951 | * |
| 1952 | * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
| 1953 | * device admins that are not device owner and not profile owner. |
| 1954 | * The password can now only be changed if there is currently no password set. Device owner |
| 1955 | * and profile owner can still do this.</em> |
| 1956 | * |
| 1957 | * <p>The given password must be sufficient for the |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1958 | * current password quality and length constraints as returned by |
| 1959 | * {@link #getPasswordQuality(ComponentName)} and |
| 1960 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1961 | * these constraints, then it will be rejected and false returned. Note |
| 1962 | * that the password may be a stronger quality (containing alphanumeric |
| 1963 | * characters when the requested quality is only numeric), in which case |
| 1964 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1965 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1966 | * <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] | 1967 | * pattern or password if the current password constraints allow it. <em>Note: This will not |
| 1968 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 1969 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 1970 | * empty, except by device owner or profile owner.</em> |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1971 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1972 | * <p>The calling device admin must have requested |
| 1973 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1974 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1975 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1976 | * @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] | 1977 | * @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] | 1978 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1979 | * @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] | 1980 | * 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] | 1981 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1982 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1983 | if (mParentInstance) { |
| 1984 | throw new SecurityException("Reset password does not work across profiles."); |
| 1985 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1986 | if (mService != null) { |
| 1987 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1988 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1989 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1990 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | return false; |
| 1994 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1995 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1996 | /** |
| 1997 | * Called by an application that is administering the device to set the |
| 1998 | * maximum time for user activity until the device will lock. This limits |
| 1999 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2000 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2001 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 2002 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2003 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2004 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2005 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2006 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 2007 | * A value of 0 means there is no restriction. |
| 2008 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2009 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2010 | if (mService != null) { |
| 2011 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2012 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2013 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2014 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2018 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2019 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2020 | * Retrieve the current maximum time to unlock for all admins of this user |
| 2021 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2022 | * @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] | 2023 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2024 | * @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] | 2025 | * 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] | 2026 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2027 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2028 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2032 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2033 | if (mService != null) { |
| 2034 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2035 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2036 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2037 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | return 0; |
| 2041 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2042 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2043 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2044 | * Make the device lock immediately, as if the lock screen timeout has |
| 2045 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2046 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2047 | * <p>The calling device admin must have requested |
| 2048 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 2049 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2050 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2051 | public void lockNow() { |
| 2052 | if (mService != null) { |
| 2053 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2054 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2055 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2056 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2057 | } |
| 2058 | } |
| 2059 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2060 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2061 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2062 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2063 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2064 | */ |
| 2065 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2066 | |
| 2067 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2068 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2069 | * data. |
| 2070 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2071 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2072 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2073 | */ |
| 2074 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2075 | |
| 2076 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 2077 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 2078 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2079 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2080 | * <p>The calling device admin must have requested |
| 2081 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 2082 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2083 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2084 | * @param flags Bit mask of additional options: currently supported flags |
| 2085 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 2086 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2087 | */ |
| 2088 | public void wipeData(int flags) { |
| 2089 | if (mService != null) { |
| 2090 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2091 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2092 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2093 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2094 | } |
| 2095 | } |
| 2096 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2097 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2098 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2099 | * Called by an application that is administering the device to set the |
| 2100 | * global proxy and exclusion list. |
| 2101 | * <p> |
| 2102 | * The calling device admin must have requested |
| 2103 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2104 | * this method; if it has not, a security exception will be thrown. |
| 2105 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2106 | * 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] | 2107 | * 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] | 2108 | * be returned. |
| 2109 | * The method can be called repeatedly by the device admin alrady setting the |
| 2110 | * proxy to update the proxy and exclusion list. |
| 2111 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2112 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2113 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2114 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2115 | * @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] | 2116 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2117 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2118 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2119 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2120 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2121 | List<String> exclusionList ) { |
| 2122 | if (proxySpec == null) { |
| 2123 | throw new NullPointerException(); |
| 2124 | } |
| 2125 | if (mService != null) { |
| 2126 | try { |
| 2127 | String hostSpec; |
| 2128 | String exclSpec; |
| 2129 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2130 | hostSpec = null; |
| 2131 | exclSpec = null; |
| 2132 | } else { |
| 2133 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2134 | throw new IllegalArgumentException(); |
| 2135 | } |
| 2136 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2137 | String hostName = sa.getHostName(); |
| 2138 | int port = sa.getPort(); |
| 2139 | StringBuilder hostBuilder = new StringBuilder(); |
| 2140 | hostSpec = hostBuilder.append(hostName) |
| 2141 | .append(":").append(Integer.toString(port)).toString(); |
| 2142 | if (exclusionList == null) { |
| 2143 | exclSpec = ""; |
| 2144 | } else { |
| 2145 | StringBuilder listBuilder = new StringBuilder(); |
| 2146 | boolean firstDomain = true; |
| 2147 | for (String exclDomain : exclusionList) { |
| 2148 | if (!firstDomain) { |
| 2149 | listBuilder = listBuilder.append(","); |
| 2150 | } else { |
| 2151 | firstDomain = false; |
| 2152 | } |
| 2153 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2154 | } |
| 2155 | exclSpec = listBuilder.toString(); |
| 2156 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2157 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2158 | != android.net.Proxy.PROXY_VALID) |
| 2159 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2160 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2161 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2162 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2163 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2164 | } |
| 2165 | } |
| 2166 | return null; |
| 2167 | } |
| 2168 | |
| 2169 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2170 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 2171 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 2172 | * doing something unusual like general internal filtering this may be useful. On |
| 2173 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 2174 | * |
| 2175 | * <p>This method requires the caller to be the device owner. |
| 2176 | * |
| 2177 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 2178 | * @see ProxyInfo |
| 2179 | * |
| 2180 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2181 | * with. |
| 2182 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 2183 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 2184 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2185 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2186 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2187 | if (mService != null) { |
| 2188 | try { |
| 2189 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2190 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2191 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2192 | } |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2197 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2198 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2199 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2200 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2201 | */ |
| 2202 | public ComponentName getGlobalProxyAdmin() { |
| 2203 | if (mService != null) { |
| 2204 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2205 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2206 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2207 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | return null; |
| 2211 | } |
| 2212 | |
| 2213 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2214 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2215 | * indicating that encryption is not supported. |
| 2216 | */ |
| 2217 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2218 | |
| 2219 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2220 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2221 | * indicating that encryption is supported, but is not currently active. |
| 2222 | */ |
| 2223 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2224 | |
| 2225 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2226 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2227 | * indicating that encryption is not currently active, but is currently |
| 2228 | * being activated. This is only reported by devices that support |
| 2229 | * encryption of data and only when the storage is currently |
| 2230 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2231 | * to become encrypted will never return this value. |
| 2232 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2233 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2234 | |
| 2235 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2236 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2237 | * indicating that encryption is active. |
| 2238 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2239 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2240 | |
| 2241 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2242 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2243 | * indicating that encryption is active, but an encryption key has not |
| 2244 | * been set by the user. |
| 2245 | */ |
| 2246 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2247 | |
| 2248 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2249 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2250 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2251 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2252 | * to check encryption status. However, on some devices this activity may never return, as |
| 2253 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2254 | */ |
| 2255 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2256 | public static final String ACTION_START_ENCRYPTION |
| 2257 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2258 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2259 | * Widgets are enabled in keyguard |
| 2260 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2261 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2262 | |
| 2263 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2264 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2265 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2266 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2267 | |
| 2268 | /** |
| 2269 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2270 | */ |
| 2271 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2272 | |
| 2273 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2274 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2275 | */ |
| 2276 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2277 | |
| 2278 | /** |
| 2279 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2280 | */ |
| 2281 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2282 | |
| 2283 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2284 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2285 | * (e.g. PIN/Pattern/Password). |
| 2286 | */ |
| 2287 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2288 | |
| 2289 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2290 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2291 | */ |
| 2292 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2293 | |
| 2294 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2295 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2296 | */ |
| 2297 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2298 | |
| 2299 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2300 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2301 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2302 | * |
| 2303 | * <p>When multiple device administrators attempt to control device |
| 2304 | * encryption, the most secure, supported setting will always be |
| 2305 | * used. If any device administrator requests device encryption, |
| 2306 | * it will be enabled; Conversely, if a device administrator |
| 2307 | * attempts to disable device encryption while another |
| 2308 | * device administrator has enabled it, the call to disable will |
| 2309 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2310 | * |
| 2311 | * <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] | 2312 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2313 | * or control the encryption of any other storage areas. |
| 2314 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2315 | * {@code true}, then the directory returned by |
| 2316 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2317 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2318 | * |
| 2319 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2320 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2321 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2322 | * also require (and check for) a pattern, PIN, or password. |
| 2323 | * |
| 2324 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2325 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2326 | * @return the new request status (for all active admins) - will be one of |
| 2327 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2328 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2329 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2330 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2331 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2332 | if (mService != null) { |
| 2333 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2334 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2335 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2336 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2337 | } |
| 2338 | } |
| 2339 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2344 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2345 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2346 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2347 | * this will return the requested encryption setting as an aggregate of all active |
| 2348 | * administrators. |
| 2349 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2350 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2351 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2352 | if (mService != null) { |
| 2353 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2354 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2355 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2356 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2357 | } |
| 2358 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2359 | return false; |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * Called by an application that is administering the device to |
| 2364 | * determine the current encryption status of the device. |
| 2365 | * |
| 2366 | * Depending on the returned status code, the caller may proceed in different |
| 2367 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2368 | * storage system does not support encryption. If the |
| 2369 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2370 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2371 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2372 | * storage system has enabled encryption but no password is set so further action |
| 2373 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2374 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2375 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2376 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2377 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2378 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2379 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2380 | */ |
| 2381 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2382 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | /** @hide per-user version */ |
| 2386 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2387 | if (mService != null) { |
| 2388 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2389 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2390 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2391 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2392 | } |
| 2393 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2394 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2395 | } |
| 2396 | |
| 2397 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2398 | * Installs the given certificate as a user CA. |
| 2399 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2400 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2401 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2402 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2403 | * |
| 2404 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2405 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2406 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2407 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2408 | if (mService != null) { |
| 2409 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2410 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2411 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2412 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2413 | } |
| 2414 | } |
| 2415 | return false; |
| 2416 | } |
| 2417 | |
| 2418 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2419 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2420 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2421 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2422 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2423 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2424 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2425 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2426 | if (mService != null) { |
| 2427 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2428 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2429 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2430 | } catch (CertificateException e) { |
| 2431 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2432 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2433 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2434 | } |
| 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2439 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2440 | * If a user has installed any certificates by other means than device policy these will be |
| 2441 | * included too. |
| 2442 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2443 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2444 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2445 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2446 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2447 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2448 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2449 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2450 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2451 | mService.enforceCanManageCaCerts(admin); |
| 2452 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2453 | for (String alias : certStore.userAliases()) { |
| 2454 | try { |
| 2455 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2456 | } catch (CertificateException ce) { |
| 2457 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2458 | } |
| 2459 | } |
| 2460 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2461 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2462 | } |
| 2463 | } |
| 2464 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2468 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2469 | * means other than device policy will also be removed, except for system CA certificates. |
| 2470 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2471 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2472 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2473 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2474 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2475 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2476 | try { |
| 2477 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2478 | .toArray(new String[0])); |
| 2479 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2480 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | /** |
| 2486 | * Returns whether this certificate is installed as a trusted CA. |
| 2487 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2488 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2489 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2490 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2491 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2492 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2493 | if (mService != null) { |
| 2494 | try { |
| 2495 | mService.enforceCanManageCaCerts(admin); |
| 2496 | return getCaCertAlias(certBuffer) != null; |
| 2497 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2498 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2499 | } catch (CertificateException ce) { |
| 2500 | Log.w(TAG, "Could not parse certificate", ce); |
| 2501 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2502 | } |
| 2503 | return false; |
| 2504 | } |
| 2505 | |
| 2506 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2507 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 2508 | * keypair will be visible to all apps within the profile. |
| 2509 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2510 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2511 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2512 | * @param privKey The private key to install. |
| 2513 | * @param cert The certificate to install. |
| 2514 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2515 | * with that alias already exists, it will be overwritten. |
| 2516 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2517 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2518 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2519 | @NonNull Certificate cert, @NonNull String alias) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2520 | try { |
| 2521 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2522 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2523 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2524 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2525 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2526 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2527 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2528 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2529 | } catch (CertificateException | IOException e) { |
| 2530 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2531 | } |
| 2532 | return false; |
| 2533 | } |
| 2534 | |
| 2535 | /** |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2536 | * Called by a device or profile owner to remove all user credentials installed under a given |
| 2537 | * alias. |
| 2538 | * |
| 2539 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2540 | * {@code null} if calling from a delegated certificate installer. |
| 2541 | * @param alias The private key alias under which the certificate is installed. |
| 2542 | * @return {@code true} if the keys were both removed, {@code false} otherwise. |
| 2543 | */ |
| 2544 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2545 | try { |
| 2546 | return mService.removeKeyPair(admin, alias); |
| 2547 | } catch (RemoteException e) { |
| 2548 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2549 | } |
| 2550 | return false; |
| 2551 | } |
| 2552 | |
| 2553 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2554 | * @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] | 2555 | * doesn't exist. |
| 2556 | */ |
| 2557 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2558 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2559 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2560 | new ByteArrayInputStream(certBuffer)); |
| 2561 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2562 | } |
| 2563 | |
| 2564 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2565 | * 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] | 2566 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2567 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2568 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2569 | * <p> |
| 2570 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2571 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2572 | * installer. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 2573 | *<p> |
| 2574 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 2575 | * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the |
| 2576 | * supplied certificate installer package must be installed when calling this API, |
| 2577 | * otherwise an {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2578 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2579 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2580 | * @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] | 2581 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2582 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2583 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2584 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2585 | if (mService != null) { |
| 2586 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2587 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2588 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2589 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | /** |
| 2595 | * 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] | 2596 | * user. null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2597 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2598 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2599 | * @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] | 2600 | * if none is set. |
| 2601 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2602 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2603 | if (mService != null) { |
| 2604 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2605 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2606 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2607 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | return null; |
| 2611 | } |
| 2612 | |
| 2613 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2614 | * Called by a device or profile owner to configure an always-on VPN connection through a |
| 2615 | * specific application for the current user. |
| 2616 | * This connection is automatically granted and persisted after a reboot. |
| 2617 | * |
| 2618 | * <p>The designated package should declare a {@link android.net.VpnService} in its |
| 2619 | * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, |
| 2620 | * otherwise the call will fail. |
| 2621 | * |
| 2622 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} |
| 2623 | * to remove an existing always-on VPN configuration. |
| 2624 | * |
| 2625 | * @return {@code true} if the package is set as always-on VPN controller; |
| 2626 | * {@code false} otherwise. |
| 2627 | */ |
| 2628 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2629 | @Nullable String vpnPackage) { |
| 2630 | if (mService != null) { |
| 2631 | try { |
| 2632 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2633 | } catch (RemoteException e) { |
| 2634 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2635 | } |
| 2636 | } |
| 2637 | return false; |
| 2638 | } |
| 2639 | |
| 2640 | /** |
| 2641 | * Called by a device or profile owner to read the name of the package administering an |
| 2642 | * always-on VPN connection for the current user. |
| 2643 | * If there is no such package, or the always-on VPN is provided by the system instead |
| 2644 | * of by an application, {@code null} will be returned. |
| 2645 | * |
| 2646 | * @return Package name of VPN controller responsible for always-on VPN, |
| 2647 | * or {@code null} if none is set. |
| 2648 | */ |
| 2649 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2650 | if (mService != null) { |
| 2651 | try { |
| 2652 | return mService.getAlwaysOnVpnPackage(admin); |
| 2653 | } catch (RemoteException e) { |
| 2654 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2655 | } |
| 2656 | } |
| 2657 | return null; |
| 2658 | } |
| 2659 | |
| 2660 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2661 | * 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] | 2662 | * on the device, for this user. After setting this, no applications running as this user |
| 2663 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2664 | * |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 2665 | * <p>If the caller is device owner, then the restriction will be applied to all users. |
| 2666 | * |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2667 | * <p>The calling device admin must have requested |
| 2668 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2669 | * this method; if it has not, a security exception will be thrown. |
| 2670 | * |
| 2671 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2672 | * @param disabled Whether or not the camera should be disabled. |
| 2673 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2674 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2675 | if (mService != null) { |
| 2676 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2677 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2678 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2679 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2680 | } |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2685 | * 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] | 2686 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2687 | * @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] | 2688 | * have disabled the camera |
| 2689 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2690 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2691 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2695 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2696 | if (mService != null) { |
| 2697 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2698 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2699 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2700 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | return false; |
| 2704 | } |
| 2705 | |
| 2706 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2707 | * Called by a device owner to request a bugreport. |
| 2708 | * |
| 2709 | * <p>There must be only one user on the device, managed by the device owner. |
| 2710 | * Otherwise a security exception will be thrown. |
| 2711 | * |
| 2712 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2713 | * @return {@code true} if the bugreport collection started successfully, or {@code false} |
| 2714 | * if it wasn't triggered because a previous bugreport operation is still active |
| 2715 | * (either the bugreport is still running or waiting for the user to share or decline) |
| 2716 | */ |
| 2717 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 2718 | if (mService != null) { |
| 2719 | try { |
| 2720 | return mService.requestBugreport(admin); |
| 2721 | } catch (RemoteException e) { |
| 2722 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2723 | } |
| 2724 | } |
| 2725 | return false; |
| 2726 | } |
| 2727 | |
| 2728 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2729 | * Determine whether or not creating a guest user has been disabled for the device |
| 2730 | * |
| 2731 | * @hide |
| 2732 | */ |
| 2733 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 2734 | // Currently guest users can always be created if multi-user is enabled |
| 2735 | // TODO introduce a policy for guest user creation |
| 2736 | return false; |
| 2737 | } |
| 2738 | |
| 2739 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2740 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2741 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2742 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2743 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2744 | * |
| 2745 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2746 | * security exception will be thrown. |
| 2747 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2748 | * <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] | 2749 | * blocks assist requests for all activities of the relevant user. |
| 2750 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2751 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2752 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2753 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2754 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2755 | if (mService != null) { |
| 2756 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2757 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2758 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2759 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2760 | } |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2765 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2766 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2767 | * @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] | 2768 | * have disabled screen capture. |
| 2769 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2770 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2771 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2775 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2776 | if (mService != null) { |
| 2777 | try { |
| 2778 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2779 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2780 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | return false; |
| 2784 | } |
| 2785 | |
| 2786 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2787 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2788 | * required the user cannot set the date and time, but has to use network date and time. |
| 2789 | * |
| 2790 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2791 | * |
| 2792 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2793 | * be thrown. |
| 2794 | * |
| 2795 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2796 | * @param required Whether auto time is set required or not. |
| 2797 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2798 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2799 | if (mService != null) { |
| 2800 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2801 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [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); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | /** |
| 2809 | * @return true if auto time is required. |
| 2810 | */ |
| 2811 | public boolean getAutoTimeRequired() { |
| 2812 | if (mService != null) { |
| 2813 | try { |
| 2814 | return mService.getAutoTimeRequired(); |
| 2815 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2816 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | return false; |
| 2820 | } |
| 2821 | |
| 2822 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 2823 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
| 2824 | * |
| 2825 | * <p>The system user is exempt from this policy - it is never ephemeral. |
| 2826 | * |
| 2827 | * <p>The calling device admin must be the device owner. If it is not, a security exception will |
| 2828 | * be thrown. |
| 2829 | * |
| 2830 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2831 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
| 2832 | * subsequently created users will be ephemeral. |
| 2833 | * @hide |
| 2834 | */ |
| 2835 | public void setForceEphemeralUsers( |
| 2836 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 2837 | if (mService != null) { |
| 2838 | try { |
| 2839 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 2840 | } catch (RemoteException e) { |
| 2841 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2842 | } |
| 2843 | } |
| 2844 | } |
| 2845 | |
| 2846 | /** |
| 2847 | * @return true if all users are created ephemeral. |
| 2848 | * @hide |
| 2849 | */ |
| 2850 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 2851 | if (mService != null) { |
| 2852 | try { |
| 2853 | return mService.getForceEphemeralUsers(admin); |
| 2854 | } catch (RemoteException e) { |
| 2855 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2856 | } |
| 2857 | } |
| 2858 | return false; |
| 2859 | } |
| 2860 | |
| 2861 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2862 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2863 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2864 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2865 | * |
| 2866 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2867 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2868 | * this method; if it has not, a security exception will be thrown. |
| 2869 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2870 | * <p>Calling this from a managed profile before version |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2871 | * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2872 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2873 | * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2874 | * <ul> |
| 2875 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT} |
| 2876 | * these will affect the profile's parent user. |
| 2877 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications |
| 2878 | * generated by applications in the managed profile. |
| 2879 | * </ul> |
| 2880 | * <p>Requests to disable other features on a managed profile will be ignored. The admin |
| 2881 | * can check which features have been disabled by calling |
| 2882 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2883 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2884 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2885 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2886 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2887 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2888 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 2889 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2890 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2891 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2892 | if (mService != null) { |
| 2893 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2894 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2895 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2896 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2897 | } |
| 2898 | } |
| 2899 | } |
| 2900 | |
| 2901 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2902 | * Determine whether or not features have been disabled in keyguard either by the calling |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2903 | * admin, if specified, or all admins. |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2904 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 2905 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2906 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2907 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2908 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2909 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2910 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2914 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2915 | if (mService != null) { |
| 2916 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2917 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2918 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2919 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2920 | } |
| 2921 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2922 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2926 | * @hide |
| 2927 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2928 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 2929 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2930 | if (mService != null) { |
| 2931 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2932 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2933 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2934 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2935 | } |
| 2936 | } |
| 2937 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2938 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2939 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2940 | * @hide |
| 2941 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2942 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2943 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2947 | * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2948 | * @hide |
| 2949 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2950 | public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2951 | ActivityInfo ai; |
| 2952 | try { |
| 2953 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2954 | PackageManager.GET_META_DATA); |
| 2955 | } catch (PackageManager.NameNotFoundException e) { |
| 2956 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2957 | return null; |
| 2958 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2959 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2960 | ResolveInfo ri = new ResolveInfo(); |
| 2961 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2962 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2963 | try { |
| 2964 | return new DeviceAdminInfo(mContext, ri); |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2965 | } catch (XmlPullParserException | IOException e) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2966 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2967 | return null; |
| 2968 | } |
| 2969 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2970 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2971 | /** |
| 2972 | * @hide |
| 2973 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2974 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2975 | if (mService != null) { |
| 2976 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2977 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2978 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2979 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2980 | } |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | /** |
| 2985 | * @hide |
| 2986 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2987 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2988 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2989 | if (mService != null) { |
| 2990 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2991 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2992 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2993 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2994 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2998 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2999 | /** |
| 3000 | * @hide |
| 3001 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3002 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3003 | if (mService != null) { |
| 3004 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3005 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3006 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3007 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3011 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3012 | /** |
| 3013 | * @hide |
| 3014 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3015 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3016 | if (mService != null) { |
| 3017 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3018 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3019 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3020 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3024 | |
| 3025 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame^] | 3026 | * @hide |
| 3027 | */ |
| 3028 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3029 | if (mService != null) { |
| 3030 | try { |
| 3031 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3032 | } catch (RemoteException e) { |
| 3033 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3034 | } |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | /** |
| 3039 | * @hide |
| 3040 | */ |
| 3041 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3042 | if (mService != null) { |
| 3043 | try { |
| 3044 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3045 | } catch (RemoteException e) { |
| 3046 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3047 | } |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3052 | * Should be called when keyguard has been dismissed. |
| 3053 | * @hide |
| 3054 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame^] | 3055 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3056 | if (mService != null) { |
| 3057 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame^] | 3058 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3059 | } catch (RemoteException e) { |
| 3060 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3061 | } |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | /** |
| 3066 | * Should be called when keyguard view has been shown to the user. |
| 3067 | * @hide |
| 3068 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame^] | 3069 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3070 | if (mService != null) { |
| 3071 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame^] | 3072 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3073 | } catch (RemoteException e) { |
| 3074 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3075 | } |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3080 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3081 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3082 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3083 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3084 | * @return whether the package was successfully registered as the device owner. |
| 3085 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3086 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3087 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3088 | public boolean setDeviceOwner(ComponentName who) { |
| 3089 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | /** |
| 3093 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3094 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3095 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3096 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | /** |
| 3100 | * @hide |
| 3101 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3102 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3103 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | /** |
| 3107 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3108 | * Sets the given package as the device owner. The package must already be installed. There |
| 3109 | * must not already be a device owner. |
| 3110 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3111 | * this method. |
| 3112 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3113 | * 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] | 3114 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3115 | * @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] | 3116 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3117 | * @return whether the package was successfully registered as the device owner. |
| 3118 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3119 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3120 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3121 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3122 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3123 | if (mService != null) { |
| 3124 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3125 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3126 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3127 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | return false; |
| 3131 | } |
| 3132 | |
| 3133 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3134 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3135 | * 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] | 3136 | * 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] | 3137 | * package is currently registered as the device owner app, pass in the package name from |
| 3138 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3139 | * 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] | 3140 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3141 | * the setup process. |
| 3142 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3143 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3144 | * @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] | 3145 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3146 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3147 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3148 | } |
| 3149 | |
| 3150 | /** |
| 3151 | * @return true if a package is registered as device owner, only when it's running on the |
| 3152 | * calling user. |
| 3153 | * |
| 3154 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3155 | * @hide |
| 3156 | */ |
| 3157 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3158 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3159 | } |
| 3160 | |
| 3161 | /** |
| 3162 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3163 | * user. |
| 3164 | * |
| 3165 | * <p>Requires the MANAGE_USERS permission. |
| 3166 | * |
| 3167 | * @hide |
| 3168 | */ |
| 3169 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3170 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3171 | } |
| 3172 | |
| 3173 | /** |
| 3174 | * @return device owner component name, only when it's running on the calling user. |
| 3175 | * |
| 3176 | * @hide |
| 3177 | */ |
| 3178 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3179 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3180 | } |
| 3181 | |
| 3182 | /** |
| 3183 | * @return device owner component name, even if it's running on a different user. |
| 3184 | * |
| 3185 | * <p>Requires the MANAGE_USERS permission. |
| 3186 | * |
| 3187 | * @hide |
| 3188 | */ |
| 3189 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3190 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3191 | } |
| 3192 | |
| 3193 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3194 | if (packageName == null) { |
| 3195 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3196 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3197 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3198 | if (deviceOwner == null) { |
| 3199 | return false; |
| 3200 | } |
| 3201 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3204 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3205 | if (mService != null) { |
| 3206 | try { |
| 3207 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3208 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3209 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3215 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3216 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3217 | * no device owner. |
| 3218 | * |
| 3219 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3220 | * |
| 3221 | * @hide |
| 3222 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3223 | public int getDeviceOwnerUserId() { |
| 3224 | if (mService != null) { |
| 3225 | try { |
| 3226 | return mService.getDeviceOwnerUserId(); |
| 3227 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3228 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3229 | } |
| 3230 | } |
| 3231 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | /** |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3235 | * Clears the current device owner. The caller must be the device owner. |
| 3236 | * |
| 3237 | * This function should be used cautiously as once it is called it cannot |
| 3238 | * be undone. The device owner can only be set as a part of device setup |
| 3239 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3240 | * |
| 3241 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3242 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3243 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3244 | if (mService != null) { |
| 3245 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3246 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3247 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3248 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3249 | } |
| 3250 | } |
| 3251 | } |
| 3252 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3253 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3254 | * Returns the device owner package name, only if it's running on the calling user. |
| 3255 | * |
| 3256 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3257 | * |
| 3258 | * @hide |
| 3259 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3260 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3261 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3262 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3263 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3267 | * @return true if the device is managed by any device owner. |
| 3268 | * |
| 3269 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3270 | * |
| 3271 | * @hide |
| 3272 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3273 | public boolean isDeviceManaged() { |
| 3274 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3275 | } |
| 3276 | |
| 3277 | /** |
| 3278 | * Returns the device owner name. Note this method *will* return the device owner |
| 3279 | * name when it's running on a different user. |
| 3280 | * |
| 3281 | * <p>Requires the MANAGE_USERS permission. |
| 3282 | * |
| 3283 | * @hide |
| 3284 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3285 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3286 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3287 | if (mService != null) { |
| 3288 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3289 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3290 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3291 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | return null; |
| 3295 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3296 | |
| 3297 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3298 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3299 | * @deprecated Do not use |
| 3300 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3301 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3302 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3303 | @SystemApi |
| 3304 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3305 | return null; |
| 3306 | } |
| 3307 | |
| 3308 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3309 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3310 | * @deprecated Do not use |
| 3311 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3312 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3313 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3314 | @SystemApi |
| 3315 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3316 | return null; |
| 3317 | } |
| 3318 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3319 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3320 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3321 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3322 | * Sets the given component as an active admin and registers the package as the profile |
| 3323 | * owner for this user. The package must already be installed and there shouldn't be |
| 3324 | * an existing profile owner registered for this user. Also, this method must be called |
| 3325 | * before the user setup has been completed. |
| 3326 | * <p> |
| 3327 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3328 | * MANAGE_DEVICE_ADMINS permission. |
| 3329 | * @param admin The component to register as an active admin and profile owner. |
| 3330 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3331 | * @return whether the admin was successfully registered as the profile owner. |
| 3332 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3333 | * the user has already been set up. |
| 3334 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3335 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3336 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3337 | throws IllegalArgumentException { |
| 3338 | if (mService != null) { |
| 3339 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3340 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3341 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3342 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3343 | } catch (RemoteException re) { |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3344 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3345 | } |
| 3346 | } |
| 3347 | return false; |
| 3348 | } |
| 3349 | |
| 3350 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3351 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 3352 | * be from the same package as the active profile owner for this user, otherwise a |
| 3353 | * SecurityException will be thrown. |
| 3354 | * |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3355 | * <p>This doesn't work for managed profile owners. |
| 3356 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3357 | * @param admin The component to remove as the profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3358 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3359 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3360 | if (mService != null) { |
| 3361 | try { |
| 3362 | mService.clearProfileOwner(admin); |
| 3363 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3364 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3365 | } |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3370 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3371 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3372 | */ |
| 3373 | public boolean hasUserSetupCompleted() { |
| 3374 | if (mService != null) { |
| 3375 | try { |
| 3376 | return mService.hasUserSetupCompleted(); |
| 3377 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3378 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3379 | } |
| 3380 | } |
| 3381 | return true; |
| 3382 | } |
| 3383 | |
| 3384 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3385 | * @hide |
| 3386 | * 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] | 3387 | * already be installed. There must not already be a profile owner for this user. |
| 3388 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3389 | * this method. |
| 3390 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3391 | * - the caller is SYSTEM_UID. |
| 3392 | * - 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] | 3393 | * @param admin the component name to be registered as profile owner. |
| 3394 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3395 | * @param userHandle the userId to set the profile owner for. |
| 3396 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3397 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3398 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3399 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3400 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3401 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3402 | if (mService != null) { |
| 3403 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3404 | if (ownerName == null) { |
| 3405 | ownerName = ""; |
| 3406 | } |
| 3407 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3408 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3409 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3410 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3411 | } |
| 3412 | } |
| 3413 | return false; |
| 3414 | } |
| 3415 | |
| 3416 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3417 | * Sets the device owner information to be shown on the lock screen. |
| 3418 | * |
| 3419 | * <p>If the device owner information is {@code null} or empty then the device owner info is |
| 3420 | * 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] | 3421 | * <p>If the device owner information contains only whitespaces then the message on the lock |
| 3422 | * 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] | 3423 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 3424 | * <p>If the device owner information needs to be localized, it is the responsibility of the |
| 3425 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3426 | * and set a new version of this string accordingly. |
| 3427 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3428 | * @param admin The name of the admin component to check. |
| 3429 | * @param info Device owner information which will be displayed instead of the user |
| 3430 | * owner info. |
| 3431 | * @return Whether the device owner information has been set. |
| 3432 | */ |
| 3433 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3434 | if (mService != null) { |
| 3435 | try { |
| 3436 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3437 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3438 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | return false; |
| 3442 | } |
| 3443 | |
| 3444 | /** |
| 3445 | * @return The device owner information. If it is not set returns {@code null}. |
| 3446 | */ |
| 3447 | public String getDeviceOwnerLockScreenInfo() { |
| 3448 | if (mService != null) { |
| 3449 | try { |
| 3450 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3451 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3452 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3453 | } |
| 3454 | } |
| 3455 | return null; |
| 3456 | } |
| 3457 | |
| 3458 | /** |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3459 | * Called by device or profile owners for setting the package suspended for this user. |
| 3460 | * A suspended package will not be started by the package manager, its notifications will |
| 3461 | * be hidden and it will not show up in recents. The package must already be installed. |
| 3462 | * |
| 3463 | * @param admin The name of the admin component to check. |
| 3464 | * @param packageName The package name of the app to suspend or unsuspend. |
| 3465 | * @param suspended If set to {@code true} than the package will be suspended, if set to |
| 3466 | * {@code false} the package will be unsuspended. |
| 3467 | * @return boolean {@code true} if the operation was successfully performed, {@code false} |
| 3468 | * otherwise. |
| 3469 | */ |
| 3470 | public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName, |
| 3471 | boolean suspended) { |
| 3472 | if (mService != null) { |
| 3473 | try { |
| 3474 | return mService.setPackageSuspended(admin, packageName, suspended); |
| 3475 | } catch (RemoteException re) { |
| 3476 | Log.w(TAG, "Failed talking with device policy service", re); |
| 3477 | } |
| 3478 | } |
| 3479 | return false; |
| 3480 | } |
| 3481 | |
| 3482 | /** |
| 3483 | * Called by device or profile owners to determine if a package is suspended. |
| 3484 | * |
| 3485 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3486 | * @param packageName The name of the package to retrieve the suspended status of. |
| 3487 | * @return boolean {@code true} if the package is suspended, {@code false} otherwise. |
| 3488 | */ |
| 3489 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3490 | if (mService != null) { |
| 3491 | try { |
| 3492 | return mService.getPackageSuspended(admin, packageName); |
| 3493 | } catch (RemoteException e) { |
| 3494 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3495 | } |
| 3496 | } |
| 3497 | return false; |
| 3498 | } |
| 3499 | |
| 3500 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3501 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3502 | * be used. Only the profile owner can call this. |
| 3503 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3504 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3505 | * |
| 3506 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3507 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3508 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3509 | if (mService != null) { |
| 3510 | try { |
| 3511 | mService.setProfileEnabled(admin); |
| 3512 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3513 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3519 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3520 | * 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] | 3521 | * never called by the profile or device owner, the name will be set to default values. |
| 3522 | * |
| 3523 | * @see #isProfileOwnerApp |
| 3524 | * @see #isDeviceOwnerApp |
| 3525 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3526 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3527 | * @param profileName The name of the profile. |
| 3528 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3529 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3530 | if (mService != null) { |
| 3531 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3532 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3533 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3534 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3535 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3536 | } |
| 3537 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3538 | |
| 3539 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3540 | * 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] | 3541 | * 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] | 3542 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3543 | * |
| 3544 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3545 | * @return Whether or not the package is registered as the profile owner. |
| 3546 | */ |
| 3547 | public boolean isProfileOwnerApp(String packageName) { |
| 3548 | if (mService != null) { |
| 3549 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 3550 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3551 | return profileOwner != null |
| 3552 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3553 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3554 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | return false; |
| 3558 | } |
| 3559 | |
| 3560 | /** |
| 3561 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3562 | * @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] | 3563 | * owner has been set for that user. |
| 3564 | * @throws IllegalArgumentException if the userId is invalid. |
| 3565 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3566 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3567 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3568 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3569 | } |
| 3570 | |
| 3571 | /** |
| 3572 | * @see #getProfileOwner() |
| 3573 | * @hide |
| 3574 | */ |
| 3575 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3576 | if (mService != null) { |
| 3577 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3578 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3579 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3580 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3581 | throw new IllegalArgumentException( |
| 3582 | "Requested profile owner for invalid userId", re); |
| 3583 | } |
| 3584 | } |
| 3585 | return null; |
| 3586 | } |
| 3587 | |
| 3588 | /** |
| 3589 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3590 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3591 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3592 | * @throws IllegalArgumentException if the userId is invalid. |
| 3593 | */ |
| 3594 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3595 | if (mService != null) { |
| 3596 | try { |
| 3597 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3598 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3599 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3600 | throw new IllegalArgumentException( |
| 3601 | "Requested profile owner for invalid userId", re); |
| 3602 | } |
| 3603 | } |
| 3604 | return null; |
| 3605 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3606 | |
| 3607 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3608 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3609 | * @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] | 3610 | * @return the human readable name of the organisation associated with this profile owner or |
| 3611 | * null if one is not set. |
| 3612 | * @throws IllegalArgumentException if the userId is invalid. |
| 3613 | */ |
| 3614 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3615 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3616 | if (mService != null) { |
| 3617 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3618 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3619 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3620 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3621 | throw new IllegalArgumentException( |
| 3622 | "Requested profile owner for invalid userId", re); |
| 3623 | } |
| 3624 | } |
| 3625 | return null; |
| 3626 | } |
| 3627 | |
| 3628 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3629 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3630 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3631 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3632 | * the intent preferences are reset. |
| 3633 | * |
| 3634 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3635 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3636 | * intent handler for the filter. |
| 3637 | * |
| 3638 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3639 | * security exception will be thrown. |
| 3640 | * |
| 3641 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3642 | * @param filter The IntentFilter for which a default handler is added. |
| 3643 | * @param activity The Activity that is added as default intent handler. |
| 3644 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3645 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3646 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3647 | if (mService != null) { |
| 3648 | try { |
| 3649 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3650 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3651 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3652 | } |
| 3653 | } |
| 3654 | } |
| 3655 | |
| 3656 | /** |
| 3657 | * 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] | 3658 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3659 | * |
| 3660 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3661 | * exception will be thrown. |
| 3662 | * |
| 3663 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3664 | * @param packageName The name of the package for which preferences are removed. |
| 3665 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3666 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3667 | String packageName) { |
| 3668 | if (mService != null) { |
| 3669 | try { |
| 3670 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3671 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3672 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3673 | } |
| 3674 | } |
| 3675 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3676 | |
| 3677 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3678 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 3679 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 3680 | * {@link #getApplicationRestrictions}. |
| 3681 | * <p> |
| 3682 | * This permission is persistent until it is later cleared by calling this method with a |
| 3683 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3684 | * <p> |
| 3685 | * The supplied application restriction managing package must be installed when calling this |
| 3686 | * API, otherwise an {@link IllegalArgumentException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3687 | * |
| 3688 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3689 | * @param packageName The package name which will be given access to application restrictions |
| 3690 | * APIs. If {@code null} is given the current package will be cleared. |
| 3691 | */ |
| 3692 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
| 3693 | @Nullable String packageName) { |
| 3694 | if (mService != null) { |
| 3695 | try { |
| 3696 | mService.setApplicationRestrictionsManagingPackage(admin, packageName); |
| 3697 | } catch (RemoteException e) { |
| 3698 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3699 | } |
| 3700 | } |
| 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 3705 | * package for the current user, or {@code null} if none is set. |
| 3706 | * |
| 3707 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3708 | * @return The package name allowed to manage application restrictions on the current user, or |
| 3709 | * {@code null} if none is set. |
| 3710 | */ |
| 3711 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 3712 | if (mService != null) { |
| 3713 | try { |
| 3714 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 3715 | } catch (RemoteException e) { |
| 3716 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3717 | } |
| 3718 | } |
| 3719 | return null; |
| 3720 | } |
| 3721 | |
| 3722 | /** |
| 3723 | * Returns {@code true} if the calling package has been granted permission via |
| 3724 | * {@link #setApplicationRestrictionsManagingPackage} to manage application |
| 3725 | * restrictions for the calling user. |
| 3726 | */ |
| 3727 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 3728 | if (mService != null) { |
| 3729 | try { |
| 3730 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 3731 | } catch (RemoteException e) { |
| 3732 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3733 | } |
| 3734 | } |
| 3735 | return false; |
| 3736 | } |
| 3737 | |
| 3738 | /** |
| 3739 | * Sets the application restrictions for a given target application running in the calling user. |
| 3740 | * |
| 3741 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 3742 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 3743 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3744 | * |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 3745 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
| 3746 | * <ul> |
| 3747 | * <li>{@code boolean} |
| 3748 | * <li>{@code int} |
| 3749 | * <li>{@code String} or {@code String[]} |
| 3750 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 3751 | * </ul> |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3752 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3753 | * <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] | 3754 | * the caller can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3755 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 3756 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3757 | * <p>The application restrictions are only made visible to the target application via |
| 3758 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or |
| 3759 | * device owner, and the application restrictions managing package via |
| 3760 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3761 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3762 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3763 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3764 | * @param packageName The name of the package to update restricted settings for. |
| 3765 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 3766 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3767 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3768 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3769 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3770 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3771 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3772 | Bundle settings) { |
| 3773 | if (mService != null) { |
| 3774 | try { |
| 3775 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3776 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3777 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3778 | } |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3783 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3784 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3785 | * trust agents but those enabled by this function call. If flag |
| 3786 | * {@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] | 3787 | * |
| 3788 | * <p>The calling device admin must have requested |
| 3789 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3790 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3791 | * |
| 3792 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3793 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3794 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3795 | * will be strictly disabled according to the state of the |
| 3796 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 3797 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 3798 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 3799 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3800 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3801 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 3802 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3803 | if (mService != null) { |
| 3804 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3805 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3806 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3807 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | |
| 3812 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3813 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 3814 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 3815 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3816 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3817 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3818 | * this function returns a list of configurations for all admins that declare |
| 3819 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 3820 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 3821 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 3822 | * 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] | 3823 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3824 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3825 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3826 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3827 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3828 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3832 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3833 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3834 | if (mService != null) { |
| 3835 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3836 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3837 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3838 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3839 | } |
| 3840 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3841 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3845 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 3846 | * 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] | 3847 | * |
| 3848 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3849 | * security exception will be thrown. |
| 3850 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3851 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3852 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 3853 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3854 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3855 | if (mService != null) { |
| 3856 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3857 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3858 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3859 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3860 | } |
| 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3865 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 3866 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3867 | * |
| 3868 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3869 | * security exception will be thrown. |
| 3870 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3872 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3873 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3874 | if (mService != null) { |
| 3875 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3876 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3877 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3878 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3879 | } |
| 3880 | } |
| 3881 | return false; |
| 3882 | } |
| 3883 | |
| 3884 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3885 | * Determine whether or not caller-Id information has been disabled. |
| 3886 | * |
| 3887 | * @param userHandle The user for whom to check the caller-id permission |
| 3888 | * @hide |
| 3889 | */ |
| 3890 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 3891 | if (mService != null) { |
| 3892 | try { |
| 3893 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 3894 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3895 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3896 | } |
| 3897 | } |
| 3898 | return false; |
| 3899 | } |
| 3900 | |
| 3901 | /** |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 3902 | * Called by a profile owner of a managed profile to set whether contacts search from |
| 3903 | * the managed profile will be shown in the parent profile, for incoming calls. |
| 3904 | * |
| 3905 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3906 | * security exception will be thrown. |
| 3907 | * |
| 3908 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3909 | * @param disabled If true contacts search in the managed profile is not displayed. |
| 3910 | */ |
| 3911 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 3912 | boolean disabled) { |
| 3913 | if (mService != null) { |
| 3914 | try { |
| 3915 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 3916 | } catch (RemoteException e) { |
| 3917 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3918 | } |
| 3919 | } |
| 3920 | } |
| 3921 | |
| 3922 | /** |
| 3923 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 3924 | * has been disabled. |
| 3925 | * |
| 3926 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3927 | * security exception will be thrown. |
| 3928 | * |
| 3929 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3930 | */ |
| 3931 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 3932 | if (mService != null) { |
| 3933 | try { |
| 3934 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 3935 | } catch (RemoteException e) { |
| 3936 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3937 | } |
| 3938 | } |
| 3939 | return false; |
| 3940 | } |
| 3941 | |
| 3942 | |
| 3943 | /** |
| 3944 | * Determine whether or not contacts search has been disabled. |
| 3945 | * |
| 3946 | * @param userHandle The user for whom to check the contacts search permission |
| 3947 | * @hide |
| 3948 | */ |
| 3949 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 3950 | if (mService != null) { |
| 3951 | try { |
| 3952 | return mService |
| 3953 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 3954 | } catch (RemoteException e) { |
| 3955 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3956 | } |
| 3957 | } |
| 3958 | return false; |
| 3959 | } |
| 3960 | |
| 3961 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3962 | * 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] | 3963 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3964 | * @hide |
| 3965 | */ |
| 3966 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3967 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3968 | if (mService != null) { |
| 3969 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3970 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 3971 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3972 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3973 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3974 | } |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3979 | * 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] | 3980 | * @hide |
| 3981 | */ |
| 3982 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 3983 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3984 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 3985 | originalIntent); |
| 3986 | } |
| 3987 | |
| 3988 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3989 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 3990 | * devices can access enterprise contacts. |
| 3991 | * <p> |
| 3992 | * The calling device admin must be a profile owner. If it is not, a |
| 3993 | * security exception will be thrown. |
| 3994 | * <p> |
| 3995 | * This API works on managed profile only. |
| 3996 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3997 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3998 | * with. |
| 3999 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 4000 | * contacts. |
| 4001 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4002 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4003 | if (mService != null) { |
| 4004 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4005 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4006 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4007 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | /** |
| 4013 | * Called by a profile owner of a managed profile to determine whether or |
| 4014 | * not Bluetooth devices cannot access enterprise contacts. |
| 4015 | * <p> |
| 4016 | * The calling device admin must be a profile owner. If it is not, a |
| 4017 | * security exception will be thrown. |
| 4018 | * <p> |
| 4019 | * This API works on managed profile only. |
| 4020 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4021 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4022 | * with. |
| 4023 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4024 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4025 | if (mService != null) { |
| 4026 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4027 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4028 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4029 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4030 | } |
| 4031 | } |
| 4032 | return true; |
| 4033 | } |
| 4034 | |
| 4035 | /** |
| 4036 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4037 | * <p> |
| 4038 | * This API works on managed profile UserHandle only. |
| 4039 | * |
| 4040 | * @param userHandle The user for whom to check the caller-id permission |
| 4041 | * @hide |
| 4042 | */ |
| 4043 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4044 | if (mService != null) { |
| 4045 | try { |
| 4046 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4047 | .getIdentifier()); |
| 4048 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4049 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4050 | } |
| 4051 | } |
| 4052 | return true; |
| 4053 | } |
| 4054 | |
| 4055 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4056 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 4057 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4058 | * Only activity intents are supported. |
| 4059 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4060 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4061 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 4062 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4063 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 4064 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4065 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4066 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4067 | if (mService != null) { |
| 4068 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4069 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4070 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4071 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4077 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4078 | * 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] | 4079 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4080 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4081 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4082 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4083 | if (mService != null) { |
| 4084 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4085 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4086 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4087 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4088 | } |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4093 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 4094 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4095 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 4096 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4097 | * By default the user can use any accessiblity service. When zero or more packages have |
| 4098 | * 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] | 4099 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4100 | * |
| 4101 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 4102 | * can be used, calling with an empty list only allows the builtin system's services. |
| 4103 | * |
| 4104 | * <p> System accesibility services are always available to the user the list can't modify |
| 4105 | * this. |
| 4106 | * |
| 4107 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4108 | * @param packageNames List of accessibility service package names. |
| 4109 | * |
| 4110 | * @return true if setting the restriction succeeded. It fail if there is |
| 4111 | * one or more non-system accessibility services enabled, that are not in the list. |
| 4112 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4113 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4114 | List<String> packageNames) { |
| 4115 | if (mService != null) { |
| 4116 | try { |
| 4117 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4118 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4119 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4120 | } |
| 4121 | } |
| 4122 | return false; |
| 4123 | } |
| 4124 | |
| 4125 | /** |
| 4126 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 4127 | * |
| 4128 | * <p>An empty list means no accessibility services except system services are allowed. |
| 4129 | * Null means all accessibility services are allowed. |
| 4130 | * |
| 4131 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4132 | * @return List of accessiblity service package names. |
| 4133 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4134 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4135 | if (mService != null) { |
| 4136 | try { |
| 4137 | return mService.getPermittedAccessibilityServices(admin); |
| 4138 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4139 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4140 | } |
| 4141 | } |
| 4142 | return null; |
| 4143 | } |
| 4144 | |
| 4145 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4146 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4147 | * |
| 4148 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4149 | * @param packageName Accessibility service package name that needs to be checked. |
| 4150 | * @param userHandle user id the admin is running as. |
| 4151 | * @return true if the accessibility service is permitted, otherwise false. |
| 4152 | * |
| 4153 | * @hide |
| 4154 | */ |
| 4155 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4156 | @NonNull String packageName, int userHandle) { |
| 4157 | if (mService != null) { |
| 4158 | try { |
| 4159 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4160 | userHandle); |
| 4161 | } catch (RemoteException e) { |
| 4162 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4163 | } |
| 4164 | } |
| 4165 | return false; |
| 4166 | } |
| 4167 | |
| 4168 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4169 | * Returns the list of accessibility services permitted by the device or profiles |
| 4170 | * owners of this user. |
| 4171 | * |
| 4172 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4173 | * it will contain the intersection of the permitted lists for any device or profile |
| 4174 | * owners that apply to this user. It will also include any system accessibility services. |
| 4175 | * |
| 4176 | * @param userId which user to check for. |
| 4177 | * @return List of accessiblity service package names. |
| 4178 | * @hide |
| 4179 | */ |
| 4180 | @SystemApi |
| 4181 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4182 | if (mService != null) { |
| 4183 | try { |
| 4184 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4185 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4186 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4187 | } |
| 4188 | } |
| 4189 | return null; |
| 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * Called by a profile or device owner to set the permitted input methods services. When |
| 4194 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4195 | * user the device owner or profile owner is an admin for. |
| 4196 | * |
| 4197 | * By default the user can use any input method. When zero or more packages have |
| 4198 | * been added, input method that are not in the list and not part of the system |
| 4199 | * can not be enabled by the user. |
| 4200 | * |
| 4201 | * This method will fail if it is called for a admin that is not for the foreground user |
| 4202 | * or a profile of the foreground user. |
| 4203 | * |
| 4204 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 4205 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 4206 | * |
| 4207 | * <p> System input methods are always available to the user this method can't modify this. |
| 4208 | * |
| 4209 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4210 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 4211 | * @return true if setting the restriction succeeded. It will fail if there are |
| 4212 | * one or more non-system input methods currently enabled that are not in |
| 4213 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4214 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4215 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4216 | if (mService != null) { |
| 4217 | try { |
| 4218 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4219 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4220 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4221 | } |
| 4222 | } |
| 4223 | return false; |
| 4224 | } |
| 4225 | |
| 4226 | |
| 4227 | /** |
| 4228 | * Returns the list of permitted input methods set by this device or profile owner. |
| 4229 | * |
| 4230 | * <p>An empty list means no input methods except system input methods are allowed. |
| 4231 | * Null means all input methods are allowed. |
| 4232 | * |
| 4233 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4234 | * @return List of input method package names. |
| 4235 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4236 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4237 | if (mService != null) { |
| 4238 | try { |
| 4239 | return mService.getPermittedInputMethods(admin); |
| 4240 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4241 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4242 | } |
| 4243 | } |
| 4244 | return null; |
| 4245 | } |
| 4246 | |
| 4247 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4248 | * Called by the system to check if a specific input method is disabled by admin. |
| 4249 | * |
| 4250 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4251 | * @param packageName Input method package name that needs to be checked. |
| 4252 | * @param userHandle user id the admin is running as. |
| 4253 | * @return true if the input method is permitted, otherwise false. |
| 4254 | * |
| 4255 | * @hide |
| 4256 | */ |
| 4257 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4258 | @NonNull String packageName, int userHandle) { |
| 4259 | if (mService != null) { |
| 4260 | try { |
| 4261 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4262 | } catch (RemoteException e) { |
| 4263 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4264 | } |
| 4265 | } |
| 4266 | return false; |
| 4267 | } |
| 4268 | |
| 4269 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4270 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4271 | * 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] | 4272 | * |
| 4273 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4274 | * it will contain the intersection of the permitted lists for any device or profile |
| 4275 | * owners that apply to this user. It will also include any system input methods. |
| 4276 | * |
| 4277 | * @return List of input method package names. |
| 4278 | * @hide |
| 4279 | */ |
| 4280 | @SystemApi |
| 4281 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4282 | if (mService != null) { |
| 4283 | try { |
| 4284 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4285 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4286 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4287 | } |
| 4288 | } |
| 4289 | return null; |
| 4290 | } |
| 4291 | |
| 4292 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4293 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4294 | * currently installed it. |
| 4295 | * |
| 4296 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4297 | * |
| 4298 | * @return List of package names to keep cached. |
| 4299 | * @hide |
| 4300 | */ |
| 4301 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4302 | if (mService != null) { |
| 4303 | try { |
| 4304 | return mService.getKeepUninstalledPackages(admin); |
| 4305 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4306 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4307 | } |
| 4308 | } |
| 4309 | return null; |
| 4310 | } |
| 4311 | |
| 4312 | /** |
| 4313 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4314 | * currently installed it. |
| 4315 | * |
| 4316 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4317 | * automatically pre-cached.</p> |
| 4318 | * |
| 4319 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4320 | * @param packageNames List of package names to keep cached. |
| 4321 | * @hide |
| 4322 | */ |
| 4323 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4324 | @NonNull List<String> packageNames) { |
| 4325 | if (mService != null) { |
| 4326 | try { |
| 4327 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4328 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4329 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4330 | } |
| 4331 | } |
| 4332 | } |
| 4333 | |
| 4334 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4335 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4336 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4337 | * created. If you need to persist an identifier for this user, use |
| 4338 | * {@link UserManager#getSerialNumberForUser}. |
| 4339 | * |
| 4340 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4341 | * @param name the user's name |
| 4342 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4343 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4344 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4345 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4346 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4347 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4348 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4349 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4350 | try { |
| 4351 | return mService.createUser(admin, name); |
| 4352 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4353 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4354 | } |
| 4355 | return null; |
| 4356 | } |
| 4357 | |
| 4358 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4359 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4360 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4361 | * created. If you need to persist an identifier for this user, use |
| 4362 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4363 | * immediately. |
| 4364 | * |
| 4365 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4366 | * as registered as an active admin on the new user. The profile owner package will be |
| 4367 | * installed on the new user if it already is installed on the device. |
| 4368 | * |
| 4369 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4370 | * profileOwnerComponent when onEnable is called. |
| 4371 | * |
| 4372 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4373 | * @param name the user's name |
| 4374 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4375 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4376 | * the user. |
| 4377 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4378 | * on the new user. |
| 4379 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4380 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4381 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4382 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4383 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4384 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4385 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4386 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4387 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4388 | try { |
| 4389 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 4390 | adminExtras); |
| 4391 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4392 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4393 | } |
| 4394 | return null; |
| 4395 | } |
| 4396 | |
| 4397 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4398 | * 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] | 4399 | */ |
| 4400 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4401 | |
| 4402 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4403 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4404 | * ephemeral. |
| 4405 | * @hide |
| 4406 | */ |
| 4407 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4408 | |
| 4409 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4410 | * Called by a device owner to create a user with the specified name and a given component of |
| 4411 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4412 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4413 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4414 | * user will not be started in the background. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4415 | * |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4416 | * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also |
| 4417 | * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and |
| 4418 | * will be registered as an active admin on the new user. The profile owner package will be |
| 4419 | * installed on the new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4420 | * |
| 4421 | * <p>If the adminExtras are not null, they will be stored on the device until the user is |
| 4422 | * started for the first time. Then the extras will be passed to the admin when |
| 4423 | * onEnable is called. |
| 4424 | * |
| 4425 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4426 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4427 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
| 4428 | * same package as admin, otherwise no user is created and an IllegalArgumentException is |
| 4429 | * thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4430 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
| 4431 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4432 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4433 | * @see UserHandle |
| 4434 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4435 | * user could not be created. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4436 | */ |
| 4437 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4438 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4439 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4440 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4441 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4442 | } catch (RemoteException re) { |
| 4443 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 4444 | } |
| 4445 | return null; |
| 4446 | } |
| 4447 | |
| 4448 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4449 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 4450 | * not be removed. |
| 4451 | * |
| 4452 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4453 | * @param userHandle the user to remove. |
| 4454 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 4455 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4456 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4457 | try { |
| 4458 | return mService.removeUser(admin, userHandle); |
| 4459 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4460 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4461 | return false; |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4466 | * Called by a device owner to switch the specified user to the foreground. |
| 4467 | * |
| 4468 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4469 | * @param userHandle the user to switch to; null will switch to primary. |
| 4470 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 4471 | * |
| 4472 | * @see Intent#ACTION_USER_FOREGROUND |
| 4473 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4474 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4475 | try { |
| 4476 | return mService.switchUser(admin, userHandle); |
| 4477 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4478 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4479 | return false; |
| 4480 | } |
| 4481 | } |
| 4482 | |
| 4483 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4484 | * Retrieves the application restrictions for a given target application running in the calling |
| 4485 | * user. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4486 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4487 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4488 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4489 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4490 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4491 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4492 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4493 | * @param packageName The name of the package to fetch restricted settings of. |
| 4494 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 4495 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 4496 | * if no restrictions have been set. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4497 | * |
| 4498 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4499 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4500 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4501 | if (mService != null) { |
| 4502 | try { |
| 4503 | return mService.getApplicationRestrictions(admin, packageName); |
| 4504 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4505 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4506 | } |
| 4507 | } |
| 4508 | return null; |
| 4509 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4510 | |
| 4511 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4512 | * 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] | 4513 | * <p> |
| 4514 | * The calling device admin must be a profile or device owner; if it is not, |
| 4515 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4516 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4517 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4518 | * with. |
| 4519 | * @param key The key of the restriction. See the constants in |
| 4520 | * {@link android.os.UserManager} for the list of keys. |
| 4521 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4522 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4523 | if (mService != null) { |
| 4524 | try { |
| 4525 | mService.setUserRestriction(admin, key, true); |
| 4526 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4527 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4528 | } |
| 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4533 | * 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] | 4534 | * <p> |
| 4535 | * The calling device admin must be a profile or device owner; if it is not, |
| 4536 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4537 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4538 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4539 | * with. |
| 4540 | * @param key The key of the restriction. See the constants in |
| 4541 | * {@link android.os.UserManager} for the list of keys. |
| 4542 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4543 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4544 | if (mService != null) { |
| 4545 | try { |
| 4546 | mService.setUserRestriction(admin, key, false); |
| 4547 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4548 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4549 | } |
| 4550 | } |
| 4551 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4552 | |
| 4553 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4554 | * Called by a profile or device owner to get user restrictions set with |
| 4555 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4556 | * <p> |
| 4557 | * The target user may have more restrictions set by the system or other device owner / profile |
| 4558 | * owner. To get all the user restrictions currently set, use |
| 4559 | * {@link UserManager#getUserRestrictions()}. |
| 4560 | * |
| 4561 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4562 | * @throws SecurityException if the {@code admin} is not an active admin. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4563 | */ |
| 4564 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4565 | return getUserRestrictions(admin, myUserId()); |
| 4566 | } |
| 4567 | |
| 4568 | /** @hide per-user version */ |
| 4569 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4570 | Bundle ret = null; |
| 4571 | if (mService != null) { |
| 4572 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4573 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4574 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4575 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4576 | } |
| 4577 | } |
| 4578 | return ret == null ? new Bundle() : ret; |
| 4579 | } |
| 4580 | |
| 4581 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4582 | * 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] | 4583 | * is unavailable for use, but the data and actual package file remain. |
| 4584 | * |
| 4585 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4586 | * @param packageName The name of the package to hide or unhide. |
| 4587 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 4588 | * unhidden. |
| 4589 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4590 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4591 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4592 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4593 | if (mService != null) { |
| 4594 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4595 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4596 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4597 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | return false; |
| 4601 | } |
| 4602 | |
| 4603 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4604 | * 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] | 4605 | * |
| 4606 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4607 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4608 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4609 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4610 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4611 | if (mService != null) { |
| 4612 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4613 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4614 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4615 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4616 | } |
| 4617 | } |
| 4618 | return false; |
| 4619 | } |
| 4620 | |
| 4621 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4622 | * 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] | 4623 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4624 | * |
| 4625 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4626 | * @param packageName The package to be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4627 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4628 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4629 | if (mService != null) { |
| 4630 | try { |
| 4631 | mService.enableSystemApp(admin, packageName); |
| 4632 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4633 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4634 | } |
| 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4639 | * 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] | 4640 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4641 | * |
| 4642 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4643 | * @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] | 4644 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4645 | * @return int The number of activities that matched the intent and were installed. |
| 4646 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4647 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4648 | if (mService != null) { |
| 4649 | try { |
| 4650 | return mService.enableSystemAppWithIntent(admin, intent); |
| 4651 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4652 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4653 | } |
| 4654 | } |
| 4655 | return 0; |
| 4656 | } |
| 4657 | |
| 4658 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4659 | * Called by a device owner or profile owner to disable account management for a specific type |
| 4660 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4661 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4662 | * <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] | 4663 | * security exception will be thrown. |
| 4664 | * |
| 4665 | * <p>When account management is disabled for an account type, adding or removing an account |
| 4666 | * of that type will not be possible. |
| 4667 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 4668 | * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
| 4669 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 4670 | * management for a specific type is disabled. |
| 4671 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4672 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4673 | * @param accountType For which account management is disabled or enabled. |
| 4674 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 4675 | * enabled (false). |
| 4676 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4677 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4678 | boolean disabled) { |
| 4679 | if (mService != null) { |
| 4680 | try { |
| 4681 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 4682 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4683 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | |
| 4688 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4689 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 4690 | * |
| 4691 | * <p> Account management can be disabled/enabled by calling |
| 4692 | * {@link #setAccountManagementDisabled}. |
| 4693 | * |
| 4694 | * @return a list of account types for which account management has been disabled. |
| 4695 | * |
| 4696 | * @see #setAccountManagementDisabled |
| 4697 | */ |
| 4698 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4699 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | /** |
| 4703 | * @see #getAccountTypesWithManagementDisabled() |
| 4704 | * @hide |
| 4705 | */ |
| 4706 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4707 | if (mService != null) { |
| 4708 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4709 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4710 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4711 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4712 | } |
| 4713 | } |
| 4714 | |
| 4715 | return null; |
| 4716 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4717 | |
| 4718 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4719 | * Sets which packages may enter lock task mode. |
| 4720 | * |
| 4721 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 4722 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4723 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4724 | * 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] | 4725 | * package list results in locked tasks belonging to those packages to be finished. |
| 4726 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 4727 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4728 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4729 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4730 | * |
| 4731 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 4732 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 4733 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 4734 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4735 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4736 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4737 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4738 | if (mService != null) { |
| 4739 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4740 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4741 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4742 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4743 | } |
| 4744 | } |
| 4745 | } |
| 4746 | |
| 4747 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4748 | * 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] | 4749 | * |
| 4750 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4751 | * @hide |
| 4752 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4753 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4754 | if (mService != null) { |
| 4755 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4756 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4757 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4758 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4759 | } |
| 4760 | } |
| 4761 | return null; |
| 4762 | } |
| 4763 | |
| 4764 | /** |
| 4765 | * This function lets the caller know whether the given component is allowed to start the |
| 4766 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4767 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4768 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4769 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4770 | if (mService != null) { |
| 4771 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4772 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [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); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | return false; |
| 4778 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4779 | |
| 4780 | /** |
| 4781 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 4782 | * 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] | 4783 | * <p>The settings that can be updated with this method are: |
| 4784 | * <ul> |
| 4785 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 4786 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 4787 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4788 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4789 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4790 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 4791 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4792 | * 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] | 4793 | * 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] | 4794 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4795 | * 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] | 4796 | * </li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4797 | * </ul> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4798 | * <p>Changing the following settings has no effect as of |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4799 | * {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4800 | * <ul> |
| 4801 | * <li>{@link Settings.Global#BLUETOOTH_ON}. |
| 4802 | * Use {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 4803 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
| 4804 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 4805 | * <li>{@link Settings.Global#MODE_RINGER}. |
| 4806 | * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
| 4807 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 4808 | * <li>{@link Settings.Global#WIFI_ON}. |
| 4809 | * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
| 4810 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4811 | * |
| 4812 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4813 | * @param setting The name of the setting to update. |
| 4814 | * @param value The value to update the setting to. |
| 4815 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4816 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4817 | if (mService != null) { |
| 4818 | try { |
| 4819 | mService.setGlobalSetting(admin, setting, value); |
| 4820 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4821 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4822 | } |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | /** |
| 4827 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 4828 | * that the value of the setting is in the correct form for the setting type should be performed |
| 4829 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4830 | * <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] | 4831 | * <ul> |
| 4832 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 4833 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4834 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 4835 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4836 | * <p>A device owner can additionally update the following settings: |
| 4837 | * <ul> |
| 4838 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 4839 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4840 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4841 | * @param setting The name of the setting to update. |
| 4842 | * @param value The value to update the setting to. |
| 4843 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4844 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4845 | if (mService != null) { |
| 4846 | try { |
| 4847 | mService.setSecureSetting(admin, setting, value); |
| 4848 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4849 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4850 | } |
| 4851 | } |
| 4852 | } |
| 4853 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4854 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4855 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4856 | * making permission requests of a local or remote administrator of the user. |
| 4857 | * <p/> |
| 4858 | * Only a profile owner can designate the restrictions provider. |
| 4859 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4860 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 4861 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4862 | * it removes the restrictions provider previously assigned. |
| 4863 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4864 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 4865 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4866 | if (mService != null) { |
| 4867 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4868 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4869 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4870 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4874 | |
| 4875 | /** |
| 4876 | * Called by profile or device owners to set the master volume mute on or off. |
| 4877 | * |
| 4878 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4879 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 4880 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4881 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4882 | if (mService != null) { |
| 4883 | try { |
| 4884 | mService.setMasterVolumeMuted(admin, on); |
| 4885 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4886 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4887 | } |
| 4888 | } |
| 4889 | } |
| 4890 | |
| 4891 | /** |
| 4892 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 4893 | * |
| 4894 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4895 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 4896 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4897 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4898 | if (mService != null) { |
| 4899 | try { |
| 4900 | return mService.isMasterVolumeMuted(admin); |
| 4901 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4902 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4903 | } |
| 4904 | } |
| 4905 | return false; |
| 4906 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4907 | |
| 4908 | /** |
| 4909 | * Called by profile or device owners to change whether a user can uninstall |
| 4910 | * a package. |
| 4911 | * |
| 4912 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4913 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4914 | * @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] | 4915 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4916 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4917 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4918 | if (mService != null) { |
| 4919 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4920 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4921 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4922 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4923 | } |
| 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4928 | * 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] | 4929 | * 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] | 4930 | * <p> |
| 4931 | * <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] | 4932 | * 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] | 4933 | * 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] | 4934 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4935 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4936 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 4937 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4938 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 4939 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4940 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4941 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4942 | if (mService != null) { |
| 4943 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 4944 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4945 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4946 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4947 | } |
| 4948 | } |
| 4949 | return false; |
| 4950 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4951 | |
| 4952 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4953 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 4954 | * 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] | 4955 | * 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] | 4956 | * 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] | 4957 | * a package may have zero or more provider components, where each component |
| 4958 | * provides a different widget type. |
| 4959 | * <p> |
| 4960 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4961 | * |
| 4962 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4963 | * @param packageName The package from which widget providers are white-listed. |
| 4964 | * @return Whether the package was added. |
| 4965 | * |
| 4966 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4967 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4968 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4969 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4970 | if (mService != null) { |
| 4971 | try { |
| 4972 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 4973 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4974 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4975 | } |
| 4976 | } |
| 4977 | return false; |
| 4978 | } |
| 4979 | |
| 4980 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4981 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 4982 | * 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] | 4983 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 4984 | * android.content.ComponentName, String)}. |
| 4985 | * <p> |
| 4986 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4987 | * |
| 4988 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4989 | * @param packageName The package from which widget providers are no longer |
| 4990 | * white-listed. |
| 4991 | * @return Whether the package was removed. |
| 4992 | * |
| 4993 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4994 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4995 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4996 | public boolean removeCrossProfileWidgetProvider( |
| 4997 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4998 | if (mService != null) { |
| 4999 | try { |
| 5000 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5001 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5002 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5003 | } |
| 5004 | } |
| 5005 | return false; |
| 5006 | } |
| 5007 | |
| 5008 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5009 | * 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] | 5010 | * available in the parent profile. |
| 5011 | * |
| 5012 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5013 | * @return The white-listed package list. |
| 5014 | * |
| 5015 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5016 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5017 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5018 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5019 | if (mService != null) { |
| 5020 | try { |
| 5021 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5022 | if (providers != null) { |
| 5023 | return providers; |
| 5024 | } |
| 5025 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5026 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | return Collections.emptyList(); |
| 5030 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5031 | |
| 5032 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5033 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5034 | * |
| 5035 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5036 | * @param icon the bitmap to set as the photo. |
| 5037 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5038 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5039 | try { |
| 5040 | mService.setUserIcon(admin, icon); |
| 5041 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5042 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5043 | } |
| 5044 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5045 | |
| 5046 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5047 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5048 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5049 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5050 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 5051 | * components in the device owner package can set system update policies and the |
| 5052 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5053 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5054 | * @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] | 5055 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5056 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5057 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5058 | if (mService != null) { |
| 5059 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5060 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5061 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5062 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5063 | } |
| 5064 | } |
| 5065 | } |
| 5066 | |
| 5067 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5068 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5069 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5070 | * @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] | 5071 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5072 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5073 | if (mService != null) { |
| 5074 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5075 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5076 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5077 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5078 | } |
| 5079 | } |
| 5080 | return null; |
| 5081 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5082 | |
| 5083 | /** |
| 5084 | * Called by a device owner to disable the keyguard altogether. |
| 5085 | * |
| 5086 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 5087 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 5088 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 5089 | * being disabled. |
| 5090 | * |
| 5091 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5092 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5093 | * |
| 5094 | * @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] | 5095 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5096 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5097 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5098 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5099 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5100 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5101 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5102 | return false; |
| 5103 | } |
| 5104 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5105 | |
| 5106 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5107 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 5108 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5109 | * a single use device. |
| 5110 | * |
| 5111 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5112 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 5113 | * |
| 5114 | * @return {@code false} if attempting to disable the status bar failed. |
| 5115 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5116 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5117 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5118 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5119 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [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); |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5122 | return false; |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5123 | } |
| 5124 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5125 | |
| 5126 | /** |
| 5127 | * Callable by the system update service to notify device owners about pending updates. |
| 5128 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5129 | * permission. |
| 5130 | * |
| 5131 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5132 | * when the current pending update was first available. -1 if no update is available. |
| 5133 | * @hide |
| 5134 | */ |
| 5135 | @SystemApi |
| 5136 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5137 | if (mService != null) { |
| 5138 | try { |
| 5139 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5140 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5141 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5142 | } |
| 5143 | } |
| 5144 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5145 | |
| 5146 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5147 | * Called by profile or device owners to set the default response for future runtime permission |
| 5148 | * requests by applications. The policy can allow for normal operation which prompts the |
| 5149 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 5150 | * 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] | 5151 | * updates. When a permission is denied or granted this way, the effect is equivalent to setting |
| 5152 | * the permission grant state via {@link #setPermissionGrantState}. |
| 5153 | * |
| 5154 | * <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] | 5155 | * 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] | 5156 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5157 | * @param admin Which profile or device owner this request is associated with. |
| 5158 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 5159 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5160 | * |
| 5161 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5162 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5163 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5164 | try { |
| 5165 | mService.setPermissionPolicy(admin, policy); |
| 5166 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5167 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5168 | } |
| 5169 | } |
| 5170 | |
| 5171 | /** |
| 5172 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5173 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5174 | * @param admin Which profile or device owner this request is associated with. |
| 5175 | * @return the current policy for future permission requests. |
| 5176 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5177 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5178 | try { |
| 5179 | return mService.getPermissionPolicy(admin); |
| 5180 | } catch (RemoteException re) { |
| 5181 | return PERMISSION_POLICY_PROMPT; |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5186 | * Sets the grant state of a runtime permission for a specific application. The state |
| 5187 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 5188 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 5189 | * is denied and the user cannot manage it through the UI, and {@link |
| 5190 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 5191 | * user cannot manage it through the UI. This might affect all permissions in a |
| 5192 | * group that the runtime permission belongs to. This method can only be called |
| 5193 | * by a profile or device owner. |
| 5194 | * |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5195 | * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not |
| 5196 | * revoke the permission. It retains the previous grant, if any. |
| 5197 | * |
| 5198 | * <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] | 5199 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5200 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5201 | * @param admin Which profile or device owner this request is associated with. |
| 5202 | * @param packageName The application to grant or revoke a permission to. |
| 5203 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5204 | * @param grantState The permission grant state which is one of {@link |
| 5205 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5206 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5207 | * @return whether the permission was successfully granted or revoked. |
| 5208 | * |
| 5209 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5210 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5211 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5212 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5213 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5214 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5215 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5216 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5217 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5218 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5219 | return false; |
| 5220 | } |
| 5221 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5222 | |
| 5223 | /** |
| 5224 | * Returns the current grant state of a runtime permission for a specific application. |
| 5225 | * |
| 5226 | * @param admin Which profile or device owner this request is associated with. |
| 5227 | * @param packageName The application to check the grant state for. |
| 5228 | * @param permission The permission to check for. |
| 5229 | * @return the current grant state specified by device policy. If the profile or device owner |
| 5230 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 5231 | * This does not indicate whether or not the permission is currently granted for the package. |
| 5232 | * |
| 5233 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 5234 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5235 | * which indicates if the permission is currently denied or granted. |
| 5236 | * |
| 5237 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5238 | * @see PackageManager#checkPermission(String, String) |
| 5239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5240 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5241 | String permission) { |
| 5242 | try { |
| 5243 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5244 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5245 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5246 | return PERMISSION_GRANT_STATE_DEFAULT; |
| 5247 | } |
| 5248 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5249 | |
| 5250 | /** |
| 5251 | * Returns if provisioning a managed profile or device is possible or not. |
| 5252 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5253 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 5254 | * Note that even if this method returns true, there is a slight possibility that the |
| 5255 | * provisioning will not be allowed when it is actually initiated because some event has |
| 5256 | * happened in between. |
| 5257 | * @return if provisioning a managed profile or device is possible or not. |
| 5258 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5259 | */ |
| 5260 | public boolean isProvisioningAllowed(String action) { |
| 5261 | try { |
| 5262 | return mService.isProvisioningAllowed(action); |
| 5263 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5264 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5265 | return false; |
| 5266 | } |
| 5267 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5268 | |
| 5269 | /** |
| 5270 | * @hide |
| 5271 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5272 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5273 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5274 | * @param admin Which profile owner this request is associated with. |
| 5275 | * @return if this user is a managed profile of another user. |
| 5276 | */ |
| 5277 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5278 | try { |
| 5279 | return mService.isManagedProfile(admin); |
| 5280 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5281 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5282 | return false; |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | /** |
| 5287 | * @hide |
| 5288 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5289 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5290 | * @param admin Which device owner this request is associated with. |
| 5291 | * @return if this user is a system-only user. |
| 5292 | */ |
| 5293 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5294 | try { |
| 5295 | return mService.isSystemOnlyUser(admin); |
| 5296 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5297 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5298 | return false; |
| 5299 | } |
| 5300 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5301 | |
| 5302 | /** |
| 5303 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5304 | * |
| 5305 | * @return the MAC address of the Wi-Fi device, or null when the information is not |
| 5306 | * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5307 | * |
| 5308 | * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5309 | */ |
| 5310 | public String getWifiMacAddress() { |
| 5311 | try { |
| 5312 | return mService.getWifiMacAddress(); |
| 5313 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5314 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5315 | return null; |
| 5316 | } |
| 5317 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5318 | |
| 5319 | /** |
| 5320 | * Called by device owner to reboot the device. |
| 5321 | */ |
| 5322 | public void reboot(@NonNull ComponentName admin) { |
| 5323 | try { |
| 5324 | mService.reboot(admin); |
| 5325 | } catch (RemoteException re) { |
| 5326 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5327 | } |
| 5328 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5329 | |
| 5330 | /** |
| 5331 | * Called by a device admin to set the short support message. This will |
| 5332 | * be displayed to the user in settings screens where funtionality has |
| 5333 | * been disabled by the admin. |
| 5334 | * |
| 5335 | * The message should be limited to a short statement such as |
| 5336 | * "This setting is disabled by your administrator. Contact someone@example.com |
| 5337 | * for support." |
| 5338 | * If the message is longer than 200 characters it may be truncated. |
| 5339 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5340 | * <p>If the short support message needs to be localized, it is the responsibility of the |
| 5341 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5342 | * and set a new version of this string accordingly. |
| 5343 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5344 | * @see #setLongSupportMessage |
| 5345 | * |
| 5346 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5347 | * @param message Short message to be displayed to the user in settings or null to |
| 5348 | * clear the existing message. |
| 5349 | */ |
| 5350 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5351 | @Nullable String message) { |
| 5352 | if (mService != null) { |
| 5353 | try { |
| 5354 | mService.setShortSupportMessage(admin, message); |
| 5355 | } catch (RemoteException e) { |
| 5356 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5357 | } |
| 5358 | } |
| 5359 | } |
| 5360 | |
| 5361 | /** |
| 5362 | * Called by a device admin to get the short support message. |
| 5363 | * |
| 5364 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5365 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5366 | * or null if no message has been set. |
| 5367 | */ |
| 5368 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5369 | if (mService != null) { |
| 5370 | try { |
| 5371 | return mService.getShortSupportMessage(admin); |
| 5372 | } catch (RemoteException e) { |
| 5373 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5374 | } |
| 5375 | } |
| 5376 | return null; |
| 5377 | } |
| 5378 | |
| 5379 | /** |
| 5380 | * Called by a device admin to set the long support message. This will |
| 5381 | * be displayed to the user in the device administators settings screen. |
| 5382 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5383 | * <p>If the long support message needs to be localized, it is the responsibility of the |
| 5384 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5385 | * and set a new version of this string accordingly. |
| 5386 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5387 | * @see #setShortSupportMessage |
| 5388 | * |
| 5389 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5390 | * @param message Long message to be displayed to the user in settings or null to |
| 5391 | * clear the existing message. |
| 5392 | */ |
| 5393 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5394 | @Nullable String message) { |
| 5395 | if (mService != null) { |
| 5396 | try { |
| 5397 | mService.setLongSupportMessage(admin, message); |
| 5398 | } catch (RemoteException e) { |
| 5399 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5400 | } |
| 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | /** |
| 5405 | * Called by a device admin to get the long support message. |
| 5406 | * |
| 5407 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5408 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5409 | * or null if no message has been set. |
| 5410 | */ |
| 5411 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5412 | if (mService != null) { |
| 5413 | try { |
| 5414 | return mService.getLongSupportMessage(admin); |
| 5415 | } catch (RemoteException e) { |
| 5416 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5417 | } |
| 5418 | } |
| 5419 | return null; |
| 5420 | } |
| 5421 | |
| 5422 | /** |
| 5423 | * Called by the system to get the short support message. |
| 5424 | * |
| 5425 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5426 | * @param userHandle user id the admin is running as. |
| 5427 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5428 | * |
| 5429 | * @hide |
| 5430 | */ |
| 5431 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5432 | if (mService != null) { |
| 5433 | try { |
| 5434 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5435 | } catch (RemoteException e) { |
| 5436 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5437 | } |
| 5438 | } |
| 5439 | return null; |
| 5440 | } |
| 5441 | |
| 5442 | |
| 5443 | /** |
| 5444 | * Called by the system to get the long support message. |
| 5445 | * |
| 5446 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5447 | * @param userHandle user id the admin is running as. |
| 5448 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5449 | * |
| 5450 | * @hide |
| 5451 | */ |
| 5452 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5453 | if (mService != null) { |
| 5454 | try { |
| 5455 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5456 | } catch (RemoteException e) { |
| 5457 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5458 | } |
| 5459 | } |
| 5460 | return null; |
| 5461 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5462 | |
| 5463 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5464 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5465 | * whose calls act on the parent profile. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5466 | * |
| 5467 | * <p> Note only some methods will work on the parent Manager. |
| 5468 | * |
| 5469 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
| 5470 | */ |
| 5471 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5472 | try { |
| 5473 | if (!mService.isManagedProfile(admin)) { |
| 5474 | throw new SecurityException("The current user does not have a parent profile."); |
| 5475 | } |
| 5476 | return new DevicePolicyManager(mContext, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5477 | } catch (RemoteException e) { |
| 5478 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5479 | return null; |
| 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | /** |
| 5484 | * Called by device owner to control the device logging feature. Logging can only be |
| 5485 | * enabled on single user devices where the sole user is managed by the device owner. |
| 5486 | * |
| 5487 | * <p> Device logs contain various information intended for security auditing purposes. |
| 5488 | * See {@link SecurityEvent} for details. |
| 5489 | * |
| 5490 | * @param admin Which device owner this request is associated with. |
| 5491 | * @param enabled whether device logging should be enabled or not. |
| 5492 | * @see #retrieveDeviceLogs |
| 5493 | */ |
| 5494 | public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 5495 | try { |
| 5496 | mService.setDeviceLoggingEnabled(admin, enabled); |
| 5497 | } catch (RemoteException re) { |
| 5498 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5499 | } |
| 5500 | } |
| 5501 | |
| 5502 | /** |
| 5503 | * Return whether device logging is enabled or not by the device owner. |
| 5504 | * |
| 5505 | * @param admin Which device owner this request is associated with. |
| 5506 | * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise. |
| 5507 | */ |
| 5508 | public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) { |
| 5509 | try { |
| 5510 | return mService.getDeviceLoggingEnabled(admin); |
| 5511 | } catch (RemoteException re) { |
| 5512 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5513 | return false; |
| 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | /** |
| 5518 | * Called by device owner to retrieve all new device logging entries since the last call to |
| 5519 | * this API after device boots. |
| 5520 | * |
| 5521 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 5522 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 5523 | * |
| 5524 | * @param admin Which device owner this request is associated with. |
| 5525 | * @return the new batch of device logs which is a list of {@link SecurityEvent}, |
| 5526 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
| 5527 | */ |
| 5528 | public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) { |
| 5529 | try { |
| 5530 | ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin); |
| 5531 | if (list != null) { |
| 5532 | return list.getList(); |
| 5533 | } else { |
| 5534 | // Rate limit exceeded. |
| 5535 | return null; |
| 5536 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5537 | } catch (RemoteException re) { |
| 5538 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5539 | return null; |
| 5540 | } |
| 5541 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5542 | |
| 5543 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 5544 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 5545 | * profile. |
| 5546 | * |
| 5547 | * @hide |
| 5548 | */ |
| 5549 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 5550 | mContext.checkSelfPermission( |
| 5551 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 5552 | if (!uInfo.isManagedProfile()) { |
| 5553 | throw new SecurityException("The user " + uInfo.id |
| 5554 | + " does not have a parent profile."); |
| 5555 | } |
| 5556 | return new DevicePolicyManager(mContext, true); |
| 5557 | } |
| 5558 | |
| 5559 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5560 | * Called by device owners to retrieve device logs from before the device's last reboot. |
| 5561 | * |
| 5562 | * <p> |
| 5563 | * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be |
| 5564 | * corruption-free during power cycles, due to hardware variations and limitations. As a |
| 5565 | * result, this API is provided as best-effort and the returned logs may contain corrupted data. |
| 5566 | * </strong> |
| 5567 | * |
| 5568 | * @param admin Which device owner this request is associated with. |
| 5569 | * @return Device logs from before the latest reboot of the system. |
| 5570 | */ |
| 5571 | public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) { |
| 5572 | try { |
| 5573 | ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin); |
| 5574 | return list.getList(); |
| 5575 | } catch (RemoteException re) { |
| 5576 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5577 | return Collections.<SecurityEvent>emptyList(); |
| 5578 | } |
| 5579 | } |
| 5580 | |
| 5581 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5582 | * Called by a profile owner of a managed profile to set the color used for customization. |
| 5583 | * This color is used as background color of the confirm credentials screen for that user. |
| 5584 | * The default color is {@link android.graphics.Color#GRAY}. |
| 5585 | * |
| 5586 | * <p>The confirm credentials screen can be created using |
| 5587 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5588 | * |
| 5589 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5590 | * @param color The 32bit representation of the color to be used. |
| 5591 | */ |
| 5592 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5593 | try { |
| 5594 | mService.setOrganizationColor(admin, color); |
| 5595 | } catch (RemoteException re) { |
| 5596 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | /** |
| 5601 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5602 | * This color is used as background color of the confirm credentials screen for that user. |
| 5603 | * |
| 5604 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5605 | * @return The 32bit representation of the color to be used. |
| 5606 | */ |
| 5607 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 5608 | try { |
| 5609 | return mService.getOrganizationColor(admin); |
| 5610 | } catch (RemoteException re) { |
| 5611 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5612 | return 0; |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | /** |
| 5617 | * @hide |
| 5618 | * Retrieve the customization color for a given user. |
| 5619 | * |
| 5620 | * @param userHandle The user id of the user we're interested in. |
| 5621 | * @return The 32bit representation of the color to be used. |
| 5622 | */ |
| 5623 | public int getOrganizationColorForUser(int userHandle) { |
| 5624 | try { |
| 5625 | return mService.getOrganizationColorForUser(userHandle); |
| 5626 | } catch (RemoteException re) { |
| 5627 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5628 | return 0; |
| 5629 | } |
| 5630 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5631 | |
| 5632 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5633 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 5634 | * management. |
| 5635 | * |
| 5636 | * <p>If the organization name needs to be localized, it is the responsibility of the |
| 5637 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5638 | * and set a new version of this string accordingly. |
| 5639 | * |
| 5640 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5641 | * @param title The organization name or {@code null} to clear a previously set name. |
| 5642 | */ |
| 5643 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 5644 | try { |
| 5645 | mService.setOrganizationName(admin, title); |
| 5646 | } catch (RemoteException re) { |
| 5647 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | /** |
| 5652 | * Called by a profile owner of a managed profile to retrieve the name of the organization |
| 5653 | * under management. |
| 5654 | * |
| 5655 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5656 | * @return The organization name or {@code null} if none is set. |
| 5657 | */ |
| 5658 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 5659 | try { |
| 5660 | return mService.getOrganizationName(admin); |
| 5661 | } catch (RemoteException re) { |
| 5662 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5663 | return null; |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | /** |
| 5668 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 5669 | * |
| 5670 | * @param userHandle The user id of the user we're interested in. |
| 5671 | * @return The organization name or {@code null} if none is set. |
| 5672 | * |
| 5673 | * @hide |
| 5674 | */ |
| 5675 | public String getOrganizationNameForUser(int userHandle) { |
| 5676 | try { |
| 5677 | return mService.getOrganizationNameForUser(userHandle); |
| 5678 | } catch (RemoteException re) { |
| 5679 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5680 | return null; |
| 5681 | } |
| 5682 | } |
| 5683 | |
| 5684 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5685 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 5686 | * return {@link #STATE_USER_UNMANAGED} |
| 5687 | * @hide |
| 5688 | */ |
| 5689 | @UserProvisioningState |
| 5690 | public int getUserProvisioningState() { |
| 5691 | if (mService != null) { |
| 5692 | try { |
| 5693 | return mService.getUserProvisioningState(); |
| 5694 | } catch (RemoteException e) { |
| 5695 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5696 | } |
| 5697 | } |
| 5698 | return STATE_USER_UNMANAGED; |
| 5699 | } |
| 5700 | |
| 5701 | /** |
| 5702 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 5703 | * |
| 5704 | * @param state to store |
| 5705 | * @param userHandle for user |
| 5706 | * @hide |
| 5707 | */ |
| 5708 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 5709 | if (mService != null) { |
| 5710 | try { |
| 5711 | mService.setUserProvisioningState(state, userHandle); |
| 5712 | } catch (RemoteException e) { |
| 5713 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5714 | } |
| 5715 | } |
| 5716 | } |
| 5717 | |
| 5718 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5719 | * @hide |
| 5720 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 5721 | * affiliated if it is managed by the same entity as the device. |
| 5722 | * |
| 5723 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 5724 | * user/profile is considered affiliated if the following conditions are both met: |
| 5725 | * <ul> |
| 5726 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 5727 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 5728 | * and a profile owner intersect, they must have come from the same source, which means that |
| 5729 | * the device owner and profile owner are controlled by the same entity.</li> |
| 5730 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 5731 | * </ul> |
| 5732 | * |
| 5733 | * @param admin Which profile or device owner this request is associated with. |
| 5734 | * @param ids A set of opaque affiliation ids. |
| 5735 | */ |
| 5736 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 5737 | try { |
| 5738 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 5739 | } catch (RemoteException e) { |
| 5740 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5741 | } |
| 5742 | } |
| 5743 | |
| 5744 | /** |
| 5745 | * @hide |
| 5746 | * Returns whether this user/profile is affiliated with the device. See |
| 5747 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 5748 | * |
| 5749 | * @return whether this user/profile is affiliated with the device. |
| 5750 | */ |
| 5751 | public boolean isAffiliatedUser() { |
| 5752 | try { |
| 5753 | return mService != null && mService.isAffiliatedUser(); |
| 5754 | } catch (RemoteException e) { |
| 5755 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5756 | return false; |
| 5757 | } |
| 5758 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 5759 | |
| 5760 | /** |
| 5761 | * @hide |
| 5762 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 5763 | * to be started |
| 5764 | * @param packageName the package to check for |
| 5765 | * @return whether the uninstall intent for {@code packageName} is pending |
| 5766 | */ |
| 5767 | public boolean isUninstallInQueue(String packageName) { |
| 5768 | try { |
| 5769 | return mService.isUninstallInQueue(packageName); |
| 5770 | } catch (RemoteException re) { |
| 5771 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5772 | return false; |
| 5773 | } |
| 5774 | } |
| 5775 | |
| 5776 | /** |
| 5777 | * @hide |
| 5778 | * @param packageName the package containing active DAs to be uninstalled |
| 5779 | */ |
| 5780 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 5781 | try { |
| 5782 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 5783 | } catch (RemoteException re) { |
| 5784 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5785 | } |
| 5786 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5787 | } |