Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 23 | import android.annotation.SdkConstant; |
| 24 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 26 | import android.annotation.UserIdInt; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 27 | import android.app.Activity; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 28 | import android.auditing.SecurityLog; |
| 29 | import android.auditing.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 30 | import android.content.ComponentName; |
| 31 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 32 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 33 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.PackageManager; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 36 | import android.content.pm.ParceledListSlice; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 37 | import android.content.pm.ResolveInfo; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 38 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 39 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 40 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 41 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 42 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 43 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 44 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 45 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 46 | import android.os.RemoteException; |
| 47 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 48 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 49 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 50 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 51 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 52 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 53 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 54 | import android.util.Log; |
| 55 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 56 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 57 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 58 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 59 | import org.xmlpull.v1.XmlPullParserException; |
| 60 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 61 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 62 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 63 | import java.lang.annotation.Retention; |
| 64 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 65 | import java.net.InetSocketAddress; |
| 66 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 67 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 68 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 69 | import java.security.PrivateKey; |
| 70 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 71 | import java.security.cert.CertificateException; |
| 72 | import java.security.cert.CertificateFactory; |
| 73 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 74 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 75 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 76 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 77 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 78 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 79 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 82 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 83 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 84 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally, |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 85 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 86 | * accessible to all device administrators unless the documentation for that method specifies that |
| 87 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 88 | * |
| 89 | * <div class="special reference"> |
| 90 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 91 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 92 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 93 | * developer guide. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 94 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 95 | */ |
| 96 | public class DevicePolicyManager { |
| 97 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | |
| 99 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 100 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 101 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 102 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 103 | private static final String REMOTE_EXCEPTION_MESSAGE = |
| 104 | "Failed to talk with device policy manager service"; |
| 105 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 106 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 107 | this(context, |
| 108 | IDevicePolicyManager.Stub.asInterface( |
| 109 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 110 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 113 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 114 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 115 | protected DevicePolicyManager( |
| 116 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | mContext = context; |
| 118 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 119 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** @hide */ |
| 123 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 124 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 125 | return me.mService != null ? me : null; |
| 126 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 127 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 128 | /** @hide test will override it. */ |
| 129 | @VisibleForTesting |
| 130 | protected int myUserId() { |
| 131 | return UserHandle.myUserId(); |
| 132 | } |
| 133 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 134 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 135 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 136 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 137 | * <p>A managed profile allows data separation for example for the usage of a |
| 138 | * device as a personal and corporate device. The user which provisioning is started from and |
| 139 | * the managed profile share a launcher. |
| 140 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 141 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 142 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 143 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 144 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 145 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 146 | * {@link #isProvisioningAllowed(String)}. |
| 147 | * |
| 148 | * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 149 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 150 | * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 151 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 152 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 153 | * |
| 154 | * <p> The intent may also contain the following extras: |
| 155 | * <ul> |
| 156 | * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li> |
| 157 | * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li> |
| 158 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 159 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 160 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 161 | * in the provisioning intent. The |
| 162 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 163 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 164 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 165 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 166 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 167 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 168 | * |
| 169 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 170 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 171 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 172 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 173 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 174 | */ |
| 175 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 176 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 177 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 178 | |
| 179 | /** |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 180 | * @hide |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 181 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 182 | * |
| 183 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 184 | * Provisioning configures the user as managed user and sets the MDM as the profile |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 185 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 186 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 187 | * allowed. |
| 188 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 189 | * <p>This intent should contain the extra |
| 190 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 191 | * |
| 192 | * <p> If provisioning fails, the device returns to its previous state. |
| 193 | * |
| 194 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 195 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 196 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 197 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 198 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 199 | */ |
| 200 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 201 | public static final String ACTION_PROVISION_MANAGED_USER |
| 202 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 203 | |
| 204 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 205 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 206 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 207 | * |
| 208 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 209 | * A device owner has full control over the device. The device owner can not be modified by the |
| 210 | * user. |
| 211 | * |
| 212 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 213 | * employee or client. |
| 214 | * |
| 215 | * <p> An intent with this action can be sent only on an unprovisioned device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 216 | * It is possible to check if provisioning is allowed or not by querying the method |
| 217 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 218 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 219 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 220 | * <ul> |
| 221 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 222 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 223 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 224 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 225 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 226 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 227 | * </ul> |
| 228 | * |
| 229 | * <p> When device owner provisioning has completed, an intent of the type |
| 230 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 231 | * device owner. |
| 232 | * |
| 233 | * <p> If provisioning fails, the device is factory reset. |
| 234 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 235 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 236 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 237 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 238 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 239 | */ |
| 240 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 241 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 242 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 243 | |
| 244 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 245 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 246 | * |
| 247 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 248 | * the device. A device owner has full control over the device. The device owner can not be |
| 249 | * modified by the user and the only way of resetting the device is via factory reset. |
| 250 | * |
| 251 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 252 | * employee or client. |
| 253 | * |
| 254 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 255 | * |
| 256 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 257 | * by a privileged app with the permission |
| 258 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 259 | * |
| 260 | * <p>The provisioning intent contains the following properties: |
| 261 | * <ul> |
| 262 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 278 | * |
| 279 | * @hide |
| 280 | */ |
| 281 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 282 | @SystemApi |
| 283 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 284 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 285 | |
| 286 | /** |
| 287 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 288 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 289 | * |
| 290 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 291 | * management state that is distinct from that reached by |
| 292 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 293 | * user, and only has control over device-wide policies, not individual users and their data. |
| 294 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 295 | * this form of device management. |
| 296 | * |
| 297 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 298 | * A device owner has full control over the device. The device owner can not be modified by the |
| 299 | * user. |
| 300 | * |
| 301 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 302 | * employee or client. |
| 303 | * |
| 304 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 305 | * It is possible to check if provisioning is allowed or not by querying the method |
| 306 | * {@link #isProvisioningAllowed(String)}. |
| 307 | * |
| 308 | * <p>The intent contains the following extras: |
| 309 | * <ul> |
| 310 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 312 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 314 | * </ul> |
| 315 | * |
| 316 | * <p> When device owner provisioning has completed, an intent of the type |
| 317 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 318 | * device owner. |
| 319 | * |
| 320 | * <p> If provisioning fails, the device is factory reset. |
| 321 | * |
| 322 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 323 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 324 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 325 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 326 | * |
| 327 | * @hide |
| 328 | */ |
| 329 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 330 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 331 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 332 | |
| 333 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 334 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 335 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 336 | * <ul> |
| 337 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 338 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 339 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 340 | * </ul> |
| 341 | * |
| 342 | * @hide |
| 343 | */ |
| 344 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 345 | public static final String ACTION_PROVISION_FINALIZATION |
| 346 | = "android.app.action.PROVISION_FINALIZATION"; |
| 347 | |
| 348 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 349 | * 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] | 350 | * allows a mobile device management application or NFC programmer application which starts |
| 351 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 352 | * <p> |
| 353 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 354 | * sends the intent to pass data to itself on the newly created profile. |
| 355 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 356 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 357 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 358 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 359 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 360 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 361 | * management application after provisioning. |
| 362 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 363 | * <p> |
| 364 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 365 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 366 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 367 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 368 | */ |
| 369 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 370 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 371 | |
| 372 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 373 | * A String extra holding the package name of the mobile device management application that |
| 374 | * will be set as the profile owner or device owner. |
| 375 | * |
| 376 | * <p>If an application starts provisioning directly via an intent with action |
| 377 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 378 | * application that started provisioning. The package will be set as profile owner in that case. |
| 379 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 380 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 381 | * 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] | 382 | * |
| 383 | * <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] | 384 | * 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] | 385 | |
| 386 | * @see DeviceAdminReceiver |
| 387 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a8 | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 388 | * supported, but only if there is only one device admin receiver in the package that requires |
| 389 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 390 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 391 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 392 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 393 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 394 | |
| 395 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 396 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 397 | * application that will be set as the profile owner or device owner and active admin. |
| 398 | * |
| 399 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 400 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 401 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 402 | * 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] | 403 | * |
| 404 | * <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] | 405 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 406 | * message containing an NFC record with MIME type |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 407 | * {@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] | 408 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 409 | * |
| 410 | * @see DeviceAdminReceiver |
| 411 | */ |
| 412 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 413 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 414 | |
| 415 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 416 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 417 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 418 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 419 | * |
| 420 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 421 | */ |
| 422 | |
| 423 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 424 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 425 | |
| 426 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 427 | * A String extra that, holds the email address of the account which a managed profile is |
| 428 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 429 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 430 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 431 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 432 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 433 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 434 | * contains this extra, it is forwarded in the |
| 435 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 436 | * device management application that was set as the profile owner during provisioning. |
| 437 | * 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] | 438 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 439 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 440 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 441 | |
| 442 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 443 | * A integer extra indicating the predominant color to show during the provisioning. |
| 444 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 445 | * |
| 446 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 447 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 448 | */ |
| 449 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 450 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 451 | |
| 452 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 453 | * 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] | 454 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 455 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 456 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 457 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 458 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 459 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 460 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 461 | |
| 462 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 463 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 464 | * will be set to. |
| 465 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 466 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 467 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 468 | */ |
| 469 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 470 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 471 | |
| 472 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 473 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 474 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 475 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 476 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 477 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 478 | */ |
| 479 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 480 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 481 | |
| 482 | /** |
| 483 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 484 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 485 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 486 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 487 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 488 | */ |
| 489 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 490 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 491 | |
| 492 | /** |
| 493 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 494 | * owner provisioning for downloading the mobile device management application. |
| 495 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 496 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 497 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 498 | */ |
| 499 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 500 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 501 | |
| 502 | /** |
| 503 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 504 | * is hidden or not. |
| 505 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 506 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 507 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 508 | */ |
| 509 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 510 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 511 | |
| 512 | /** |
| 513 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 514 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 515 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 516 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 517 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 518 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 519 | */ |
| 520 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 521 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * A String extra holding the password of the wifi network in |
| 525 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 526 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 527 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 528 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 529 | */ |
| 530 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 531 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 532 | |
| 533 | /** |
| 534 | * A String extra holding the proxy host for the wifi network in |
| 535 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 536 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 537 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 538 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 539 | */ |
| 540 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 541 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 542 | |
| 543 | /** |
| 544 | * An int extra holding the proxy port for the wifi network in |
| 545 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 546 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 547 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 548 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 549 | */ |
| 550 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 551 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 552 | |
| 553 | /** |
| 554 | * A String extra holding the proxy bypass for the wifi network in |
| 555 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 556 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 557 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 558 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 559 | */ |
| 560 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 561 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 562 | |
| 563 | /** |
| 564 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 565 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 566 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 567 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 568 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 569 | */ |
| 570 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 571 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 572 | |
| 573 | /** |
| 574 | * A String extra holding a url that specifies the download location of the device admin |
| 575 | * package. When not provided it is assumed that the device admin package is already installed. |
| 576 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 577 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 578 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 579 | */ |
| 580 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 581 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 582 | |
| 583 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 584 | * An int extra holding a minimum required version code for the device admin package. If the |
| 585 | * device admin is already installed on the device, it will only be re-downloaded from |
| 586 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 587 | * installed package is less than this version code. |
| 588 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 589 | * <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] | 590 | * provisioning via an NFC bump. |
| 591 | */ |
| 592 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 593 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 594 | |
| 595 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 596 | * A String extra holding a http cookie header which should be used in the http request to the |
| 597 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 598 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 599 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 600 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 601 | */ |
| 602 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 603 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 604 | |
| 605 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 606 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 607 | * the file at download location specified in |
| 608 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 609 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 610 | * <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] | 611 | * present. The provided checksum should match the checksum of the file at the download |
| 612 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 613 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 614 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 615 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 616 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 617 | * |
| 618 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 619 | * 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] | 620 | * 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] | 621 | * 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] | 622 | */ |
| 623 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 624 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 625 | |
| 626 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 627 | * 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] | 628 | * android package archive at the download location specified in {@link |
| 629 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 630 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 631 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 632 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 633 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 634 | * |
| 635 | * <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] | 636 | * 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] | 637 | * the download location. If the checksum does not match an error will be shown to the user and |
| 638 | * the user will be asked to factory reset the device. |
| 639 | * |
| 640 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 641 | * provisioning via an NFC bump. |
| 642 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 643 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 644 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 645 | |
| 646 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 647 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 648 | * has completed successfully. |
| 649 | * |
| 650 | * <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] | 651 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 652 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 653 | * <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] | 654 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 655 | */ |
| 656 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 657 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 658 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 659 | |
| 660 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 661 | * 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] | 662 | * provisioning. |
| 663 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 664 | * <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] | 665 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 666 | */ |
| 667 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 668 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 669 | |
| 670 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 671 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 672 | * provisioning. If this extra is not passed, a default image will be shown. |
| 673 | * <h5>The following URI schemes are accepted:</h5> |
| 674 | * <ul> |
| 675 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 676 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 677 | * </ul> |
| 678 | * |
| 679 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 680 | * pixed density for the device. |
| 681 | * |
| 682 | * <p> If a content: URI is passed, the intent should have the flag |
| 683 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 684 | * {@link android.content.ClipData} of the intent too. |
| 685 | * |
| 686 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 687 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 688 | */ |
| 689 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 690 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 691 | |
| 692 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 693 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 694 | * during setup-wizard. |
| 695 | * |
| 696 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 697 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 698 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 699 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 700 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 701 | * |
| 702 | * @hide |
| 703 | */ |
| 704 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 705 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 706 | |
| 707 | /** |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 708 | * This MIME type is used for starting the Device Owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 709 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 710 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 711 | * A device owner has full control over the device. The device owner can not be modified by the |
| 712 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 713 | * reset. |
| 714 | * |
| 715 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 716 | * employee or client. |
| 717 | * |
| 718 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 719 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 720 | * <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] | 721 | * contains the following properties: |
| 722 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 723 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 724 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 725 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 726 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 727 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 728 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 729 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 730 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 731 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 732 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 733 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 734 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 735 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 736 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 737 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 738 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 739 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 740 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 741 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 742 | * 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] | 743 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 744 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 745 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 746 | */ |
| 747 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 748 | = "application/com.android.managedprovisioning"; |
| 749 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 750 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 751 | * Activity action: ask the user to add a new device administrator to the system. |
| 752 | * The desired policy is the ComponentName of the policy in the |
| 753 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 754 | * bring the user through adding the device administrator to the system (or |
| 755 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 756 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 757 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 758 | * field to provide the user with additional explanation (in addition |
| 759 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 760 | * |
| 761 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 762 | * user intervention). However, if your administrator has been updated and is requesting |
| 763 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 764 | * 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] | 765 | */ |
| 766 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 767 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 768 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 769 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 770 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 771 | * @hide |
| 772 | * 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] | 773 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 774 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 775 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 776 | * 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] | 777 | * to remotely control restrictions on the user. |
| 778 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 779 | * <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] | 780 | * result of whether or not the user approved the action. If approved, the result will |
| 781 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 782 | * as a profile owner. |
| 783 | * |
| 784 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 785 | * field to provide the user with additional explanation (in addition |
| 786 | * to your component's description) about what is being added. |
| 787 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 788 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 789 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 790 | */ |
| 791 | @SystemApi |
| 792 | public static final String ACTION_SET_PROFILE_OWNER |
| 793 | = "android.app.action.SET_PROFILE_OWNER"; |
| 794 | |
| 795 | /** |
| 796 | * @hide |
| 797 | * Name of the profile owner admin that controls the user. |
| 798 | */ |
| 799 | @SystemApi |
| 800 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 801 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 802 | |
| 803 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 804 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 805 | * 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] | 806 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 807 | * @hide |
| 808 | */ |
| 809 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 810 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 811 | |
| 812 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 813 | * Broadcast action: sent when the device owner is set or changed. |
| 814 | * |
| 815 | * This broadcast is sent only to the primary user. |
| 816 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 817 | */ |
| 818 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 819 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 820 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 821 | |
| 822 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 823 | * The ComponentName of the administrator component. |
| 824 | * |
| 825 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 826 | */ |
| 827 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 828 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 829 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 830 | * An optional CharSequence providing additional explanation for why the |
| 831 | * admin is being added. |
| 832 | * |
| 833 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 834 | */ |
| 835 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 836 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 837 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 838 | * Activity action: have the user enter a new password. This activity should |
| 839 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 840 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 841 | * enter a new password that meets the current requirements. You can use |
| 842 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 843 | * have the user select a new password in order to meet the current |
| 844 | * constraints. Upon being resumed from this activity, you can check the new |
| 845 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 846 | * |
| 847 | * If the intent is launched from within a managed profile with a profile |
| 848 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 849 | * this will trigger entering a new password for the parent of the profile. |
| 850 | * For all other cases it will trigger entering a new password for the user |
| 851 | * or profile it is launched from. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 852 | */ |
| 853 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 854 | public static final String ACTION_SET_NEW_PASSWORD |
| 855 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 856 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 857 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 858 | * Activity action: have the user enter a new password for the parent profile. |
| 859 | * If the intent is launched from within a managed profile, this will trigger |
| 860 | * entering a new password for the parent of the profile. In all other cases |
| 861 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 862 | */ |
| 863 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 864 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 865 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 866 | |
| 867 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 868 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 869 | * the parent profile to access intents sent from the managed profile. |
| 870 | * That is, when an app in the managed profile calls |
| 871 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 872 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 873 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 874 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 875 | |
| 876 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 877 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 878 | * the managed profile to access intents sent from the parent profile. |
| 879 | * That is, when an app in the parent profile calls |
| 880 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 881 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 882 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 883 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 884 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 885 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 886 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 887 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 888 | */ |
| 889 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 890 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 891 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 892 | |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 893 | /** |
| 894 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 895 | * Already granted or denied permissions are not affected by this. |
| 896 | */ |
| 897 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 898 | |
| 899 | /** |
| 900 | * Permission policy to always grant new permission requests for runtime permissions. |
| 901 | * Already granted or denied permissions are not affected by this. |
| 902 | */ |
| 903 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 904 | |
| 905 | /** |
| 906 | * Permission policy to always deny new permission requests for runtime permissions. |
| 907 | * Already granted or denied permissions are not affected by this. |
| 908 | */ |
| 909 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 910 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 911 | /** |
| 912 | * Runtime permission state: The user can manage the permission |
| 913 | * through the UI. |
| 914 | */ |
| 915 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 916 | |
| 917 | /** |
| 918 | * Runtime permission state: The permission is granted to the app |
| 919 | * and the user cannot manage the permission through the UI. |
| 920 | */ |
| 921 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 922 | |
| 923 | /** |
| 924 | * Runtime permission state: The permission is denied to the app |
| 925 | * and the user cannot manage the permission through the UI. |
| 926 | */ |
| 927 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 928 | |
| 929 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 930 | * No management for current user in-effect. This is the default. |
| 931 | * @hide |
| 932 | */ |
| 933 | public static final int STATE_USER_UNMANAGED = 0; |
| 934 | |
| 935 | /** |
| 936 | * Management partially setup, user setup needs to be completed. |
| 937 | * @hide |
| 938 | */ |
| 939 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 940 | |
| 941 | /** |
| 942 | * Management partially setup, user setup completed. |
| 943 | * @hide |
| 944 | */ |
| 945 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 946 | |
| 947 | /** |
| 948 | * Management setup and active on current user. |
| 949 | * @hide |
| 950 | */ |
| 951 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 952 | |
| 953 | /** |
| 954 | * Management partially setup on a managed profile. |
| 955 | * @hide |
| 956 | */ |
| 957 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 958 | |
| 959 | /** |
| 960 | * @hide |
| 961 | */ |
| 962 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 963 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 964 | @Retention(RetentionPolicy.SOURCE) |
| 965 | public @interface UserProvisioningState {} |
| 966 | |
| 967 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 968 | * Return true if the given administrator component is currently |
| 969 | * active (enabled) in the system. |
| 970 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 971 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 972 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | /** |
| 976 | * @see #isAdminActive(ComponentName) |
| 977 | * @hide |
| 978 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 979 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 980 | if (mService != null) { |
| 981 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 982 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 983 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 984 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | return false; |
| 988 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 989 | /** |
| 990 | * Return true if the given administrator component is currently being removed |
| 991 | * for the user. |
| 992 | * @hide |
| 993 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 994 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 995 | if (mService != null) { |
| 996 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 997 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 998 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 999 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | return false; |
| 1003 | } |
| 1004 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1005 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1006 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1007 | * Return a list of all currently active device administrators' component |
| 1008 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1009 | * returned. |
| 1010 | */ |
| 1011 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1012 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /** |
| 1016 | * @see #getActiveAdmins() |
| 1017 | * @hide |
| 1018 | */ |
| 1019 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1020 | if (mService != null) { |
| 1021 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1022 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1023 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1024 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | return null; |
| 1028 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1029 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1030 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1031 | * Used by package administration code to determine if a package can be stopped |
| 1032 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1033 | * @hide |
| 1034 | */ |
| 1035 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame^] | 1036 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * Used by package administration code to determine if a package can be stopped |
| 1041 | * or uninstalled. |
| 1042 | * @hide |
| 1043 | */ |
| 1044 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1045 | if (mService != null) { |
| 1046 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame^] | 1047 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1048 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1049 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | return false; |
| 1053 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1054 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1055 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1056 | * Remove a current administration component. This can only be called |
| 1057 | * by the application that owns the administration component; if you |
| 1058 | * try to remove someone else's component, a security exception will be |
| 1059 | * thrown. |
| 1060 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1061 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1062 | if (mService != null) { |
| 1063 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1064 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1065 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1066 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1070 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1071 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1072 | * 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] | 1073 | * 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] | 1074 | * but requires additional policies after an upgrade. |
| 1075 | * |
| 1076 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 1077 | * an active administrator, or an exception will be thrown. |
| 1078 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 1079 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1080 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1081 | if (mService != null) { |
| 1082 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1083 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1084 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1085 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1092 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1093 | * |
| 1094 | * @hide |
| 1095 | */ |
| 1096 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1097 | if (mService != null) { |
| 1098 | try { |
| 1099 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1100 | } catch (RemoteException e) { |
| 1101 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1102 | } |
| 1103 | } |
| 1104 | return false; |
| 1105 | } |
| 1106 | |
| 1107 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1108 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1109 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1110 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1111 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1112 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1113 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1114 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1115 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1116 | * recognition technology. This implies technologies that can recognize the identity of |
| 1117 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1118 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1119 | */ |
| 1120 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1121 | |
| 1122 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1123 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1124 | * 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] | 1125 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1126 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1127 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1128 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1129 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1130 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1131 | * password containing at least numeric characters. Note that quality |
| 1132 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1133 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1134 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1135 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1136 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1137 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1138 | * password containing at least numeric characters with no repeating (4444) |
| 1139 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1140 | * constants are ordered so that higher values are more restrictive. |
| 1141 | */ |
| 1142 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1143 | |
| 1144 | /** |
| 1145 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1146 | * password containing at least alphabetic (or other symbol) characters. |
| 1147 | * Note that quality constants are ordered so that higher values are more |
| 1148 | * restrictive. |
| 1149 | */ |
| 1150 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1151 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1152 | /** |
| 1153 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1154 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1155 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1156 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1157 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1158 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1159 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1160 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1161 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1162 | * password containing at least a letter, a numerical digit and a special |
| 1163 | * symbol, by default. With this password quality, passwords can be |
| 1164 | * restricted to contain various sets of characters, like at least an |
| 1165 | * uppercase letter, etc. These are specified using various methods, |
| 1166 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1167 | * that quality constants are ordered so that higher values are more |
| 1168 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1169 | */ |
| 1170 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1171 | |
| 1172 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1173 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1174 | * modify password. In case this password quality is set, the password is |
| 1175 | * managed by a profile owner. The profile owner can set any password, |
| 1176 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1177 | * that quality constants are ordered so that higher values are more |
| 1178 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1179 | * the highest. |
| 1180 | * @hide |
| 1181 | */ |
| 1182 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1183 | |
| 1184 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1185 | * Called by an application that is administering the device to set the |
| 1186 | * password restrictions it is imposing. After setting this, the user |
| 1187 | * will not be able to enter a new password that is not at least as |
| 1188 | * restrictive as what has been set. Note that the current password |
| 1189 | * will remain until the user has set a new one, so the change does not |
| 1190 | * take place immediately. To prompt the user for a new password, use |
| 1191 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1192 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1193 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 1194 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1195 | * the user's preference, and any other considerations) is the one that |
| 1196 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1197 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1198 | * <p>The calling device admin must have requested |
| 1199 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1200 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1201 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1202 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1203 | * @param quality The new desired quality. One of |
| 1204 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1205 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1206 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1207 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1208 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1209 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1210 | if (mService != null) { |
| 1211 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1212 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1213 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1214 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1218 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1219 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1220 | * Retrieve the current minimum password quality for all admins of this user |
| 1221 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1222 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1223 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1224 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1225 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1226 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1230 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1231 | if (mService != null) { |
| 1232 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1233 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1234 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1235 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1236 | } |
| 1237 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1238 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1239 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1240 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1241 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1242 | * Called by an application that is administering the device to set the |
| 1243 | * minimum allowed password length. After setting this, the user |
| 1244 | * will not be able to enter a new password that is not at least as |
| 1245 | * restrictive as what has been set. Note that the current password |
| 1246 | * will remain until the user has set a new one, so the change does not |
| 1247 | * take place immediately. To prompt the user for a new password, use |
| 1248 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1249 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1250 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1251 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1252 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1253 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1254 | * <p>The calling device admin must have requested |
| 1255 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1256 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1257 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1258 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1259 | * @param length The new desired minimum password length. A value of 0 |
| 1260 | * means there is no restriction. |
| 1261 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1262 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1263 | if (mService != null) { |
| 1264 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1265 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1266 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1267 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1271 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1272 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1273 | * Retrieve the current minimum password length for all admins of this |
| 1274 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1275 | * @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] | 1276 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1277 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1278 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1279 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1283 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1284 | if (mService != null) { |
| 1285 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1286 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1287 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1288 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | return 0; |
| 1292 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1293 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1294 | /** |
| 1295 | * Called by an application that is administering the device to set the |
| 1296 | * minimum number of upper case letters required in the password. After |
| 1297 | * setting this, the user will not be able to enter a new password that is |
| 1298 | * not at least as restrictive as what has been set. Note that the current |
| 1299 | * password will remain until the user has set a new one, so the change does |
| 1300 | * not take place immediately. To prompt the user for a new password, use |
| 1301 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1302 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1303 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1304 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1305 | * <p> |
| 1306 | * The calling device admin must have requested |
| 1307 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1308 | * this method; if it has not, a security exception will be thrown. |
| 1309 | * |
| 1310 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1311 | * with. |
| 1312 | * @param length The new desired minimum number of upper case letters |
| 1313 | * required in the password. A value of 0 means there is no |
| 1314 | * restriction. |
| 1315 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1316 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1317 | if (mService != null) { |
| 1318 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1319 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1320 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1321 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1328 | * password for all admins of this user and its profiles or a particular one. |
| 1329 | * This is the same value as set by |
| 1330 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1331 | * and only applies when the password quality is |
| 1332 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1333 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1334 | * @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] | 1335 | * aggregate all admins. |
| 1336 | * @return The minimum number of upper case letters required in the |
| 1337 | * password. |
| 1338 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1339 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1340 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1344 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1345 | if (mService != null) { |
| 1346 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1347 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1348 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1349 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
| 1355 | /** |
| 1356 | * Called by an application that is administering the device to set the |
| 1357 | * minimum number of lower case letters required in the password. After |
| 1358 | * setting this, the user will not be able to enter a new password that is |
| 1359 | * not at least as restrictive as what has been set. Note that the current |
| 1360 | * password will remain until the user has set a new one, so the change does |
| 1361 | * not take place immediately. To prompt the user for a new password, use |
| 1362 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1363 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1364 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1365 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1366 | * <p> |
| 1367 | * The calling device admin must have requested |
| 1368 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1369 | * this method; if it has not, a security exception will be thrown. |
| 1370 | * |
| 1371 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1372 | * with. |
| 1373 | * @param length The new desired minimum number of lower case letters |
| 1374 | * required in the password. A value of 0 means there is no |
| 1375 | * restriction. |
| 1376 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1377 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1378 | if (mService != null) { |
| 1379 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1380 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1381 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1382 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | /** |
| 1388 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1389 | * password for all admins of this user and its profiles or a particular one. |
| 1390 | * This is the same value as set by |
| 1391 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1392 | * and only applies when the password quality is |
| 1393 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1394 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1395 | * @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] | 1396 | * aggregate all admins. |
| 1397 | * @return The minimum number of lower case letters required in the |
| 1398 | * password. |
| 1399 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1400 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1401 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1405 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1406 | if (mService != null) { |
| 1407 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1408 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1409 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1410 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1411 | } |
| 1412 | } |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | /** |
| 1417 | * Called by an application that is administering the device to set the |
| 1418 | * minimum number of letters required in the password. After setting this, |
| 1419 | * the user will not be able to enter a new password that is not at least as |
| 1420 | * restrictive as what has been set. Note that the current password will |
| 1421 | * remain until the user has set a new one, so the change does not take |
| 1422 | * place immediately. To prompt the user for a new password, use |
| 1423 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1424 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1425 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1426 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1427 | * <p> |
| 1428 | * The calling device admin must have requested |
| 1429 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1430 | * this method; if it has not, a security exception will be thrown. |
| 1431 | * |
| 1432 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1433 | * with. |
| 1434 | * @param length The new desired minimum number of letters required in the |
| 1435 | * password. A value of 0 means there is no restriction. |
| 1436 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1437 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1438 | if (mService != null) { |
| 1439 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1440 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1441 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1442 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1449 | * admins or a particular one. This is the same value as |
| 1450 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 1451 | * and only applies when the password quality is |
| 1452 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1453 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1454 | * @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] | 1455 | * aggregate all admins. |
| 1456 | * @return The minimum number of letters required in the password. |
| 1457 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1458 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1459 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1463 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1464 | if (mService != null) { |
| 1465 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1466 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1467 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1468 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
| 1474 | /** |
| 1475 | * Called by an application that is administering the device to set the |
| 1476 | * minimum number of numerical digits required in the password. After |
| 1477 | * setting this, the user will not be able to enter a new password that is |
| 1478 | * not at least as restrictive as what has been set. Note that the current |
| 1479 | * password will remain until the user has set a new one, so the change does |
| 1480 | * not take place immediately. To prompt the user for a new password, use |
| 1481 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1482 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1483 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1484 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1485 | * <p> |
| 1486 | * The calling device admin must have requested |
| 1487 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1488 | * this method; if it has not, a security exception will be thrown. |
| 1489 | * |
| 1490 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1491 | * with. |
| 1492 | * @param length The new desired minimum number of numerical digits required |
| 1493 | * in the password. A value of 0 means there is no restriction. |
| 1494 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1495 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1496 | if (mService != null) { |
| 1497 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1498 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1499 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1500 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | /** |
| 1506 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1507 | * for all admins of this user and its profiles or a particular one. |
| 1508 | * This is the same value as set by |
| 1509 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1510 | * and only applies when the password quality is |
| 1511 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1512 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1513 | * @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] | 1514 | * aggregate all admins. |
| 1515 | * @return The minimum number of numerical digits required in the password. |
| 1516 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1517 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1518 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1522 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1523 | if (mService != null) { |
| 1524 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1525 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1526 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1527 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1528 | } |
| 1529 | } |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * Called by an application that is administering the device to set the |
| 1535 | * minimum number of symbols required in the password. After setting this, |
| 1536 | * the user will not be able to enter a new password that is not at least as |
| 1537 | * restrictive as what has been set. Note that the current password will |
| 1538 | * remain until the user has set a new one, so the change does not take |
| 1539 | * place immediately. To prompt the user for a new password, use |
| 1540 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1541 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1542 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1543 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1544 | * <p> |
| 1545 | * The calling device admin must have requested |
| 1546 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1547 | * this method; if it has not, a security exception will be thrown. |
| 1548 | * |
| 1549 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1550 | * with. |
| 1551 | * @param length The new desired minimum number of symbols required in the |
| 1552 | * password. A value of 0 means there is no restriction. |
| 1553 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1554 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1555 | if (mService != null) { |
| 1556 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1557 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1558 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1559 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1560 | } |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | /** |
| 1565 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1566 | * admins or a particular one. This is the same value as |
| 1567 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1568 | * and only applies when the password quality is |
| 1569 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1570 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1571 | * @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] | 1572 | * aggregate all admins. |
| 1573 | * @return The minimum number of symbols required in the password. |
| 1574 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1575 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1576 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1580 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1581 | if (mService != null) { |
| 1582 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1583 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1584 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1585 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1586 | } |
| 1587 | } |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1591 | /** |
| 1592 | * Called by an application that is administering the device to set the |
| 1593 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1594 | * required in the password. After setting this, the user will not be able |
| 1595 | * to enter a new password that is not at least as restrictive as what has |
| 1596 | * been set. Note that the current password will remain until the user has |
| 1597 | * set a new one, so the change does not take place immediately. To prompt |
| 1598 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1599 | * setting this value. This constraint is only imposed if the administrator |
| 1600 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1601 | * {@link #setPasswordQuality}. The default value is 0. |
| 1602 | * <p> |
| 1603 | * The calling device admin must have requested |
| 1604 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1605 | * this method; if it has not, a security exception will be thrown. |
| 1606 | * |
| 1607 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1608 | * with. |
| 1609 | * @param length The new desired minimum number of letters required in the |
| 1610 | * password. A value of 0 means there is no restriction. |
| 1611 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1612 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1613 | if (mService != null) { |
| 1614 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1615 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1616 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1617 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | /** |
| 1623 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1624 | * password for all admins of this user and its profiles or a particular one. |
| 1625 | * This is the same value as set by |
| 1626 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1627 | * and only applies when the password quality is |
| 1628 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1629 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1630 | * @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] | 1631 | * aggregate all admins. |
| 1632 | * @return The minimum number of letters required in the password. |
| 1633 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1634 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1635 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1639 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1640 | if (mService != null) { |
| 1641 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1642 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1643 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1644 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1650 | /** |
| 1651 | * Called by an application that is administering the device to set the length |
| 1652 | * of the password history. After setting this, the user will not be able to |
| 1653 | * enter a new password that is the same as any password in the history. Note |
| 1654 | * that the current password will remain until the user has set a new one, so |
| 1655 | * the change does not take place immediately. To prompt the user for a new |
| 1656 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1657 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1658 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1659 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1660 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1661 | * |
| 1662 | * <p> |
| 1663 | * The calling device admin must have requested |
| 1664 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1665 | * method; if it has not, a security exception will be thrown. |
| 1666 | * |
| 1667 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1668 | * with. |
| 1669 | * @param length The new desired length of password history. A value of 0 |
| 1670 | * means there is no restriction. |
| 1671 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1672 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1673 | if (mService != null) { |
| 1674 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1675 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1676 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1677 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1683 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1684 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1685 | * the device password (for all admins). |
| 1686 | * |
| 1687 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1688 | * For example, to have the password expire 5 days from now, timeout would be |
| 1689 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1690 | * |
| 1691 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1692 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1693 | * <p>The calling device admin must have requested |
| 1694 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1695 | * method; if it has not, a security exception will be thrown. |
| 1696 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1697 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1698 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1699 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1700 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1701 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1702 | * means there is no restriction (unlimited). |
| 1703 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1704 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1705 | if (mService != null) { |
| 1706 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1707 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1708 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1709 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1715 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1716 | * recurring expiration timeout provided in the call to |
| 1717 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1718 | * aggregate of all policy administrators if {@code admin} is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1719 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1720 | * @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] | 1721 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1722 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1723 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1724 | if (mService != null) { |
| 1725 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1726 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1727 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1728 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1729 | } |
| 1730 | } |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
| 1734 | /** |
| 1735 | * 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] | 1736 | * all admins of this user and its profiles if admin is null. If the password is |
| 1737 | * expired, this will return the time since the password expired as a negative number. |
| 1738 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1739 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1740 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1741 | * @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] | 1742 | * @return The password expiration time, in ms. |
| 1743 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1744 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1745 | if (mService != null) { |
| 1746 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1747 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1748 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1749 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1750 | } |
| 1751 | } |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1756 | * Retrieve the current password history length for all admins of this |
| 1757 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1758 | * @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] | 1759 | * all admins. |
| 1760 | * @return The length of the password history |
| 1761 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1762 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1763 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1767 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1768 | if (mService != null) { |
| 1769 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1770 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1771 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1772 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1773 | } |
| 1774 | } |
| 1775 | return 0; |
| 1776 | } |
| 1777 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1778 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1779 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1780 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1781 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1782 | * @return Returns the maximum length that the user can enter. |
| 1783 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1784 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1785 | // Kind-of arbitrary. |
| 1786 | return 16; |
| 1787 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1788 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1789 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1790 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1791 | * to meet the policy requirements (quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1792 | * 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] | 1793 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1794 | * <p>The calling device admin must have requested |
| 1795 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1796 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1797 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1798 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1799 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1800 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1801 | if (mService != null) { |
| 1802 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1803 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1804 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1805 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1806 | } |
| 1807 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1808 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1809 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1810 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1811 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 1812 | * Determine whether the current profile password the user has set is sufficient |
| 1813 | * to meet the policy requirements (quality, minimum length) that have been |
| 1814 | * requested by the admins of the parent user and its profiles. |
| 1815 | * |
| 1816 | * @param userHandle the userId of the profile to check the password for. |
| 1817 | * @return Returns true if the password would meet the current requirements, else false. |
| 1818 | * @hide |
| 1819 | */ |
| 1820 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 1821 | if (mService != null) { |
| 1822 | try { |
| 1823 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 1824 | } catch (RemoteException e) { |
| 1825 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 1826 | } |
| 1827 | } |
| 1828 | return false; |
| 1829 | } |
| 1830 | |
| 1831 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1832 | * Retrieve the number of times the user has failed at entering a |
| 1833 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1834 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1835 | * <p>The calling device admin must have requested |
| 1836 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1837 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1838 | */ |
| 1839 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 1840 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 1841 | } |
| 1842 | |
| 1843 | /** |
| 1844 | * Retrieve the number of times the given user has failed at entering a |
| 1845 | * password since that last successful password entry. |
| 1846 | * |
| 1847 | * <p>The calling device admin must have requested |
| 1848 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 1849 | * not and it is not the system uid, a security exception will be thrown. |
| 1850 | * |
| 1851 | * @hide |
| 1852 | */ |
| 1853 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1854 | if (mService != null) { |
| 1855 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 1856 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1857 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1858 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | return -1; |
| 1862 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1863 | |
| 1864 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1865 | * 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] | 1866 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1867 | * @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] | 1868 | * @hide |
| 1869 | */ |
| 1870 | public boolean getDoNotAskCredentialsOnBoot() { |
| 1871 | if (mService != null) { |
| 1872 | try { |
| 1873 | return mService.getDoNotAskCredentialsOnBoot(); |
| 1874 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1875 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | return false; |
| 1879 | } |
| 1880 | |
| 1881 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1882 | * Setting this to a value greater than zero enables a built-in policy |
| 1883 | * that will perform a device wipe after too many incorrect |
| 1884 | * device-unlock passwords have been entered. This built-in policy combines |
| 1885 | * watching for failed passwords and wiping the device, and requires |
| 1886 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1887 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1888 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1889 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1890 | * application only, erasing or revoking credentials, or reporting the |
| 1891 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1892 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1893 | * instead. Do not use this API, because if the maximum count is reached, |
| 1894 | * 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] | 1895 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1896 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1897 | * @param num The number of failed password attempts at which point the |
| 1898 | * device will wipe its data. |
| 1899 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1900 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1901 | if (mService != null) { |
| 1902 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1903 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1904 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1905 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1909 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1910 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1911 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1912 | * 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] | 1913 | * or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1914 | * @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] | 1915 | * all admins. |
| 1916 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1917 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1918 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1922 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1923 | if (mService != null) { |
| 1924 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1925 | return mService.getMaximumFailedPasswordsForWipe( |
| 1926 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1927 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1928 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | return 0; |
| 1932 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1933 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1934 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1935 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1936 | * for the given user. So for primary user, it might return the primary or |
| 1937 | * a managed profile. For a secondary user, it would be the same as the |
| 1938 | * user passed in. |
| 1939 | * @hide Used only by Keyguard |
| 1940 | */ |
| 1941 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1942 | if (mService != null) { |
| 1943 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1944 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 1945 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1946 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 1947 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | return UserHandle.USER_NULL; |
| 1951 | } |
| 1952 | |
| 1953 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1954 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1955 | * the password again until the user has entered it. |
| 1956 | */ |
| 1957 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1958 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1959 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1960 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 1961 | * If the flag is set, the device can be booted without asking for user password. |
| 1962 | * The absence of this flag does not change the current boot requirements. This flag |
| 1963 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 1964 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 1965 | * device to factory defaults. |
| 1966 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1967 | 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] | 1968 | |
| 1969 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1970 | * Force a new device unlock password (the password needed to access the |
| 1971 | * entire device, not for individual accounts) on the user. This takes |
| 1972 | * effect immediately. |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 1973 | * |
| 1974 | * <p>Calling this from a managed profile that shares the password with the owner profile |
| 1975 | * will throw a security exception. |
| 1976 | * |
| 1977 | * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
| 1978 | * device admins that are not device owner and not profile owner. |
| 1979 | * The password can now only be changed if there is currently no password set. Device owner |
| 1980 | * and profile owner can still do this.</em> |
| 1981 | * |
| 1982 | * <p>The given password must be sufficient for the |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1983 | * current password quality and length constraints as returned by |
| 1984 | * {@link #getPasswordQuality(ComponentName)} and |
| 1985 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1986 | * these constraints, then it will be rejected and false returned. Note |
| 1987 | * that the password may be a stronger quality (containing alphanumeric |
| 1988 | * characters when the requested quality is only numeric), in which case |
| 1989 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1990 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1991 | * <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] | 1992 | * pattern or password if the current password constraints allow it. <em>Note: This will not |
| 1993 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 1994 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 1995 | * empty, except by device owner or profile owner.</em> |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1996 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1997 | * <p>The calling device admin must have requested |
| 1998 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1999 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2000 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2001 | * @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] | 2002 | * @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] | 2003 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2004 | * @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] | 2005 | * 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] | 2006 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2007 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2008 | if (mParentInstance) { |
| 2009 | throw new SecurityException("Reset password does not work across profiles."); |
| 2010 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2011 | if (mService != null) { |
| 2012 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2013 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2014 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2015 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2016 | } |
| 2017 | } |
| 2018 | return false; |
| 2019 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2020 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2021 | /** |
| 2022 | * Called by an application that is administering the device to set the |
| 2023 | * maximum time for user activity until the device will lock. This limits |
| 2024 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2025 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2026 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 2027 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2028 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2029 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2030 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2031 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 2032 | * A value of 0 means there is no restriction. |
| 2033 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2034 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2035 | if (mService != null) { |
| 2036 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2037 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2038 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2039 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2040 | } |
| 2041 | } |
| 2042 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2043 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2044 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2045 | * Retrieve the current maximum time to unlock for all admins of this user |
| 2046 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2047 | * @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] | 2048 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2049 | * @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] | 2050 | * 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] | 2051 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2052 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2053 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2057 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2058 | if (mService != null) { |
| 2059 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2060 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2061 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2062 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | return 0; |
| 2066 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2067 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2068 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2069 | * Make the device lock immediately, as if the lock screen timeout has |
| 2070 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2071 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2072 | * <p>The calling device admin must have requested |
| 2073 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 2074 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2075 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2076 | public void lockNow() { |
| 2077 | if (mService != null) { |
| 2078 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2079 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2080 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2081 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2082 | } |
| 2083 | } |
| 2084 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2085 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2086 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2087 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2088 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2089 | */ |
| 2090 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2091 | |
| 2092 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2093 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2094 | * data. |
| 2095 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2096 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2097 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2098 | */ |
| 2099 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2100 | |
| 2101 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 2102 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 2103 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2104 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2105 | * <p>The calling device admin must have requested |
| 2106 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 2107 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2108 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2109 | * @param flags Bit mask of additional options: currently supported flags |
| 2110 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 2111 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2112 | */ |
| 2113 | public void wipeData(int flags) { |
| 2114 | if (mService != null) { |
| 2115 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2116 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2117 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2118 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2122 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2123 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2124 | * Called by an application that is administering the device to set the |
| 2125 | * global proxy and exclusion list. |
| 2126 | * <p> |
| 2127 | * The calling device admin must have requested |
| 2128 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2129 | * this method; if it has not, a security exception will be thrown. |
| 2130 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2131 | * 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] | 2132 | * 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] | 2133 | * be returned. |
| 2134 | * The method can be called repeatedly by the device admin alrady setting the |
| 2135 | * proxy to update the proxy and exclusion list. |
| 2136 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2137 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2138 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2139 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2140 | * @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] | 2141 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2142 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2143 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2144 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2145 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2146 | List<String> exclusionList ) { |
| 2147 | if (proxySpec == null) { |
| 2148 | throw new NullPointerException(); |
| 2149 | } |
| 2150 | if (mService != null) { |
| 2151 | try { |
| 2152 | String hostSpec; |
| 2153 | String exclSpec; |
| 2154 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2155 | hostSpec = null; |
| 2156 | exclSpec = null; |
| 2157 | } else { |
| 2158 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2159 | throw new IllegalArgumentException(); |
| 2160 | } |
| 2161 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2162 | String hostName = sa.getHostName(); |
| 2163 | int port = sa.getPort(); |
| 2164 | StringBuilder hostBuilder = new StringBuilder(); |
| 2165 | hostSpec = hostBuilder.append(hostName) |
| 2166 | .append(":").append(Integer.toString(port)).toString(); |
| 2167 | if (exclusionList == null) { |
| 2168 | exclSpec = ""; |
| 2169 | } else { |
| 2170 | StringBuilder listBuilder = new StringBuilder(); |
| 2171 | boolean firstDomain = true; |
| 2172 | for (String exclDomain : exclusionList) { |
| 2173 | if (!firstDomain) { |
| 2174 | listBuilder = listBuilder.append(","); |
| 2175 | } else { |
| 2176 | firstDomain = false; |
| 2177 | } |
| 2178 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2179 | } |
| 2180 | exclSpec = listBuilder.toString(); |
| 2181 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2182 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2183 | != android.net.Proxy.PROXY_VALID) |
| 2184 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2185 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2186 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2187 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2188 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2189 | } |
| 2190 | } |
| 2191 | return null; |
| 2192 | } |
| 2193 | |
| 2194 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2195 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 2196 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 2197 | * doing something unusual like general internal filtering this may be useful. On |
| 2198 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 2199 | * |
| 2200 | * <p>This method requires the caller to be the device owner. |
| 2201 | * |
| 2202 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 2203 | * @see ProxyInfo |
| 2204 | * |
| 2205 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2206 | * with. |
| 2207 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 2208 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 2209 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2210 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2211 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2212 | if (mService != null) { |
| 2213 | try { |
| 2214 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2215 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2216 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2222 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2223 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2224 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2225 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2226 | */ |
| 2227 | public ComponentName getGlobalProxyAdmin() { |
| 2228 | if (mService != null) { |
| 2229 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2230 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2231 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2232 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | return null; |
| 2236 | } |
| 2237 | |
| 2238 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2239 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2240 | * indicating that encryption is not supported. |
| 2241 | */ |
| 2242 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2243 | |
| 2244 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2245 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2246 | * indicating that encryption is supported, but is not currently active. |
| 2247 | */ |
| 2248 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2249 | |
| 2250 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2251 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2252 | * indicating that encryption is not currently active, but is currently |
| 2253 | * being activated. This is only reported by devices that support |
| 2254 | * encryption of data and only when the storage is currently |
| 2255 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2256 | * to become encrypted will never return this value. |
| 2257 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2258 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2259 | |
| 2260 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2261 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2262 | * indicating that encryption is active. |
| 2263 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2264 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2265 | |
| 2266 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2267 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2268 | * indicating that encryption is active, but an encryption key has not |
| 2269 | * been set by the user. |
| 2270 | */ |
| 2271 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2272 | |
| 2273 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2274 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2275 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2276 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2277 | * to check encryption status. However, on some devices this activity may never return, as |
| 2278 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2279 | */ |
| 2280 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2281 | public static final String ACTION_START_ENCRYPTION |
| 2282 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2283 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2284 | * Widgets are enabled in keyguard |
| 2285 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2286 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2287 | |
| 2288 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2289 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2290 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2291 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2292 | |
| 2293 | /** |
| 2294 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2295 | */ |
| 2296 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2297 | |
| 2298 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2299 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2300 | */ |
| 2301 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2302 | |
| 2303 | /** |
| 2304 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2305 | */ |
| 2306 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2307 | |
| 2308 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2309 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2310 | * (e.g. PIN/Pattern/Password). |
| 2311 | */ |
| 2312 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2313 | |
| 2314 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2315 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2316 | */ |
| 2317 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2318 | |
| 2319 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2320 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2321 | */ |
| 2322 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2323 | |
| 2324 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2325 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2326 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2327 | * |
| 2328 | * <p>When multiple device administrators attempt to control device |
| 2329 | * encryption, the most secure, supported setting will always be |
| 2330 | * used. If any device administrator requests device encryption, |
| 2331 | * it will be enabled; Conversely, if a device administrator |
| 2332 | * attempts to disable device encryption while another |
| 2333 | * device administrator has enabled it, the call to disable will |
| 2334 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2335 | * |
| 2336 | * <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] | 2337 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2338 | * or control the encryption of any other storage areas. |
| 2339 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2340 | * {@code true}, then the directory returned by |
| 2341 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2342 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2343 | * |
| 2344 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2345 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2346 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2347 | * also require (and check for) a pattern, PIN, or password. |
| 2348 | * |
| 2349 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2350 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2351 | * @return the new request status (for all active admins) - will be one of |
| 2352 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2353 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2354 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2355 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2356 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2357 | if (mService != null) { |
| 2358 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2359 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2360 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2361 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2362 | } |
| 2363 | } |
| 2364 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2365 | } |
| 2366 | |
| 2367 | /** |
| 2368 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2369 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2370 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2371 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2372 | * this will return the requested encryption setting as an aggregate of all active |
| 2373 | * administrators. |
| 2374 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2375 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2376 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2377 | if (mService != null) { |
| 2378 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2379 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2380 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2381 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2382 | } |
| 2383 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2384 | return false; |
| 2385 | } |
| 2386 | |
| 2387 | /** |
| 2388 | * Called by an application that is administering the device to |
| 2389 | * determine the current encryption status of the device. |
| 2390 | * |
| 2391 | * Depending on the returned status code, the caller may proceed in different |
| 2392 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2393 | * storage system does not support encryption. If the |
| 2394 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2395 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2396 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2397 | * storage system has enabled encryption but no password is set so further action |
| 2398 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2399 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2400 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2401 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2402 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2403 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2404 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2405 | */ |
| 2406 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2407 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | /** @hide per-user version */ |
| 2411 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2412 | if (mService != null) { |
| 2413 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2414 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2415 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2416 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2417 | } |
| 2418 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2419 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2420 | } |
| 2421 | |
| 2422 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2423 | * Installs the given certificate as a user CA. |
| 2424 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2425 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2426 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2427 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2428 | * |
| 2429 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2430 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2431 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2432 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2433 | if (mService != null) { |
| 2434 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2435 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2436 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2437 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | return false; |
| 2441 | } |
| 2442 | |
| 2443 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2444 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2445 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2446 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2447 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2448 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2449 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2450 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2451 | if (mService != null) { |
| 2452 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2453 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2454 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2455 | } catch (CertificateException e) { |
| 2456 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2457 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2458 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2464 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2465 | * If a user has installed any certificates by other means than device policy these will be |
| 2466 | * included too. |
| 2467 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2468 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2469 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2470 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2471 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2472 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2473 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2474 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2475 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2476 | mService.enforceCanManageCaCerts(admin); |
| 2477 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2478 | for (String alias : certStore.userAliases()) { |
| 2479 | try { |
| 2480 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2481 | } catch (CertificateException ce) { |
| 2482 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2483 | } |
| 2484 | } |
| 2485 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2486 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2487 | } |
| 2488 | } |
| 2489 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2493 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2494 | * means other than device policy will also be removed, except for system CA certificates. |
| 2495 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2496 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2497 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2498 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2499 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2500 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2501 | try { |
| 2502 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2503 | .toArray(new String[0])); |
| 2504 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2505 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | /** |
| 2511 | * Returns whether this certificate is installed as a trusted CA. |
| 2512 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2513 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2514 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2515 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2516 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2517 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2518 | if (mService != null) { |
| 2519 | try { |
| 2520 | mService.enforceCanManageCaCerts(admin); |
| 2521 | return getCaCertAlias(certBuffer) != null; |
| 2522 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2523 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2524 | } catch (CertificateException ce) { |
| 2525 | Log.w(TAG, "Could not parse certificate", ce); |
| 2526 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2527 | } |
| 2528 | return false; |
| 2529 | } |
| 2530 | |
| 2531 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2532 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 2533 | * keypair will be visible to all apps within the profile. |
| 2534 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2535 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2536 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2537 | * @param privKey The private key to install. |
| 2538 | * @param cert The certificate to install. |
| 2539 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2540 | * with that alias already exists, it will be overwritten. |
| 2541 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2542 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2543 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2544 | @NonNull Certificate cert, @NonNull String alias) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2545 | try { |
| 2546 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2547 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2548 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2549 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2550 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2551 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2552 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2553 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2554 | } catch (CertificateException | IOException e) { |
| 2555 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2556 | } |
| 2557 | return false; |
| 2558 | } |
| 2559 | |
| 2560 | /** |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2561 | * Called by a device or profile owner to remove all user credentials installed under a given |
| 2562 | * alias. |
| 2563 | * |
| 2564 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2565 | * {@code null} if calling from a delegated certificate installer. |
| 2566 | * @param alias The private key alias under which the certificate is installed. |
| 2567 | * @return {@code true} if the keys were both removed, {@code false} otherwise. |
| 2568 | */ |
| 2569 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2570 | try { |
| 2571 | return mService.removeKeyPair(admin, alias); |
| 2572 | } catch (RemoteException e) { |
| 2573 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2574 | } |
| 2575 | return false; |
| 2576 | } |
| 2577 | |
| 2578 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2579 | * @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] | 2580 | * doesn't exist. |
| 2581 | */ |
| 2582 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2583 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2584 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2585 | new ByteArrayInputStream(certBuffer)); |
| 2586 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2587 | } |
| 2588 | |
| 2589 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2590 | * 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] | 2591 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2592 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2593 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2594 | * <p> |
| 2595 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2596 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2597 | * installer. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 2598 | *<p> |
| 2599 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 2600 | * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the |
| 2601 | * supplied certificate installer package must be installed when calling this API, |
| 2602 | * otherwise an {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2603 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2604 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2605 | * @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] | 2606 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2607 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2608 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2609 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2610 | if (mService != null) { |
| 2611 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2612 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2613 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2614 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2615 | } |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | /** |
| 2620 | * 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] | 2621 | * user. null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2622 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2623 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2624 | * @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] | 2625 | * if none is set. |
| 2626 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2627 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2628 | if (mService != null) { |
| 2629 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2630 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2631 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2632 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | return null; |
| 2636 | } |
| 2637 | |
| 2638 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2639 | * Called by a device or profile owner to configure an always-on VPN connection through a |
| 2640 | * specific application for the current user. |
| 2641 | * This connection is automatically granted and persisted after a reboot. |
| 2642 | * |
| 2643 | * <p>The designated package should declare a {@link android.net.VpnService} in its |
| 2644 | * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, |
| 2645 | * otherwise the call will fail. |
| 2646 | * |
| 2647 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} |
| 2648 | * to remove an existing always-on VPN configuration. |
| 2649 | * |
| 2650 | * @return {@code true} if the package is set as always-on VPN controller; |
| 2651 | * {@code false} otherwise. |
| 2652 | */ |
| 2653 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2654 | @Nullable String vpnPackage) { |
| 2655 | if (mService != null) { |
| 2656 | try { |
| 2657 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2658 | } catch (RemoteException e) { |
| 2659 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2660 | } |
| 2661 | } |
| 2662 | return false; |
| 2663 | } |
| 2664 | |
| 2665 | /** |
| 2666 | * Called by a device or profile owner to read the name of the package administering an |
| 2667 | * always-on VPN connection for the current user. |
| 2668 | * If there is no such package, or the always-on VPN is provided by the system instead |
| 2669 | * of by an application, {@code null} will be returned. |
| 2670 | * |
| 2671 | * @return Package name of VPN controller responsible for always-on VPN, |
| 2672 | * or {@code null} if none is set. |
| 2673 | */ |
| 2674 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2675 | if (mService != null) { |
| 2676 | try { |
| 2677 | return mService.getAlwaysOnVpnPackage(admin); |
| 2678 | } catch (RemoteException e) { |
| 2679 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2680 | } |
| 2681 | } |
| 2682 | return null; |
| 2683 | } |
| 2684 | |
| 2685 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2686 | * 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] | 2687 | * on the device, for this user. After setting this, no applications running as this user |
| 2688 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2689 | * |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 2690 | * <p>If the caller is device owner, then the restriction will be applied to all users. |
| 2691 | * |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2692 | * <p>The calling device admin must have requested |
| 2693 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2694 | * this method; if it has not, a security exception will be thrown. |
| 2695 | * |
| 2696 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2697 | * @param disabled Whether or not the camera should be disabled. |
| 2698 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2699 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2700 | if (mService != null) { |
| 2701 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2702 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2703 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2704 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2705 | } |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2710 | * 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] | 2711 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2712 | * @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] | 2713 | * have disabled the camera |
| 2714 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2715 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2716 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2720 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2721 | if (mService != null) { |
| 2722 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2723 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2724 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2725 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | return false; |
| 2729 | } |
| 2730 | |
| 2731 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2732 | * Called by a device owner to request a bugreport. |
| 2733 | * |
| 2734 | * <p>There must be only one user on the device, managed by the device owner. |
| 2735 | * Otherwise a security exception will be thrown. |
| 2736 | * |
| 2737 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2738 | * @return {@code true} if the bugreport collection started successfully, or {@code false} |
| 2739 | * if it wasn't triggered because a previous bugreport operation is still active |
| 2740 | * (either the bugreport is still running or waiting for the user to share or decline) |
| 2741 | */ |
| 2742 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 2743 | if (mService != null) { |
| 2744 | try { |
| 2745 | return mService.requestBugreport(admin); |
| 2746 | } catch (RemoteException e) { |
| 2747 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2748 | } |
| 2749 | } |
| 2750 | return false; |
| 2751 | } |
| 2752 | |
| 2753 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2754 | * Determine whether or not creating a guest user has been disabled for the device |
| 2755 | * |
| 2756 | * @hide |
| 2757 | */ |
| 2758 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 2759 | // Currently guest users can always be created if multi-user is enabled |
| 2760 | // TODO introduce a policy for guest user creation |
| 2761 | return false; |
| 2762 | } |
| 2763 | |
| 2764 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2765 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2766 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2767 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2768 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2769 | * |
| 2770 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2771 | * security exception will be thrown. |
| 2772 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2773 | * <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] | 2774 | * blocks assist requests for all activities of the relevant user. |
| 2775 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2776 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2777 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2778 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2779 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2780 | if (mService != null) { |
| 2781 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2782 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2783 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2784 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2790 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2791 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2792 | * @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] | 2793 | * have disabled screen capture. |
| 2794 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2795 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2796 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2800 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2801 | if (mService != null) { |
| 2802 | try { |
| 2803 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2804 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2805 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | return false; |
| 2809 | } |
| 2810 | |
| 2811 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2812 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2813 | * required the user cannot set the date and time, but has to use network date and time. |
| 2814 | * |
| 2815 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2816 | * |
| 2817 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2818 | * be thrown. |
| 2819 | * |
| 2820 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2821 | * @param required Whether auto time is set required or not. |
| 2822 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2823 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2824 | if (mService != null) { |
| 2825 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2826 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2827 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2828 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2829 | } |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | /** |
| 2834 | * @return true if auto time is required. |
| 2835 | */ |
| 2836 | public boolean getAutoTimeRequired() { |
| 2837 | if (mService != null) { |
| 2838 | try { |
| 2839 | return mService.getAutoTimeRequired(); |
| 2840 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2841 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | return false; |
| 2845 | } |
| 2846 | |
| 2847 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 2848 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
| 2849 | * |
| 2850 | * <p>The system user is exempt from this policy - it is never ephemeral. |
| 2851 | * |
| 2852 | * <p>The calling device admin must be the device owner. If it is not, a security exception will |
| 2853 | * be thrown. |
| 2854 | * |
| 2855 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2856 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
| 2857 | * subsequently created users will be ephemeral. |
| 2858 | * @hide |
| 2859 | */ |
| 2860 | public void setForceEphemeralUsers( |
| 2861 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 2862 | if (mService != null) { |
| 2863 | try { |
| 2864 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 2865 | } catch (RemoteException e) { |
| 2866 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2867 | } |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | /** |
| 2872 | * @return true if all users are created ephemeral. |
| 2873 | * @hide |
| 2874 | */ |
| 2875 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 2876 | if (mService != null) { |
| 2877 | try { |
| 2878 | return mService.getForceEphemeralUsers(admin); |
| 2879 | } catch (RemoteException e) { |
| 2880 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 2881 | } |
| 2882 | } |
| 2883 | return false; |
| 2884 | } |
| 2885 | |
| 2886 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2887 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2888 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2889 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2890 | * |
| 2891 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2892 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2893 | * this method; if it has not, a security exception will be thrown. |
| 2894 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2895 | * <p>Calling this from a managed profile before version |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2896 | * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2897 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 2898 | * <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] | 2899 | * <ul> |
| 2900 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT} |
| 2901 | * these will affect the profile's parent user. |
| 2902 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications |
| 2903 | * generated by applications in the managed profile. |
| 2904 | * </ul> |
| 2905 | * <p>Requests to disable other features on a managed profile will be ignored. The admin |
| 2906 | * can check which features have been disabled by calling |
| 2907 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2908 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2909 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2910 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2911 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2912 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2913 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 2914 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2915 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2916 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2917 | if (mService != null) { |
| 2918 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2919 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2920 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2921 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2922 | } |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 2927 | * 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] | 2928 | * admin, if specified, or all admins. |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2929 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 2930 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2931 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2932 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2933 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2934 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2935 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2939 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2940 | if (mService != null) { |
| 2941 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2942 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2943 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2944 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2945 | } |
| 2946 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2947 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2951 | * @hide |
| 2952 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2953 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 2954 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2955 | if (mService != null) { |
| 2956 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2957 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2958 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2959 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2960 | } |
| 2961 | } |
| 2962 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2963 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2964 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2965 | * @hide |
| 2966 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2967 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2968 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2972 | * 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] | 2973 | * @hide |
| 2974 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2975 | public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2976 | ActivityInfo ai; |
| 2977 | try { |
| 2978 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2979 | PackageManager.GET_META_DATA); |
| 2980 | } catch (PackageManager.NameNotFoundException e) { |
| 2981 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2982 | return null; |
| 2983 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2984 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2985 | ResolveInfo ri = new ResolveInfo(); |
| 2986 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2987 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2988 | try { |
| 2989 | return new DeviceAdminInfo(mContext, ri); |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 2990 | } catch (XmlPullParserException | IOException e) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2991 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2992 | return null; |
| 2993 | } |
| 2994 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2995 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2996 | /** |
| 2997 | * @hide |
| 2998 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2999 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3000 | if (mService != null) { |
| 3001 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3002 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3003 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3004 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | /** |
| 3010 | * @hide |
| 3011 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3012 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3013 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3014 | if (mService != null) { |
| 3015 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3016 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3017 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3018 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3019 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3020 | } |
| 3021 | } |
| 3022 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3023 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3024 | /** |
| 3025 | * @hide |
| 3026 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3027 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3028 | if (mService != null) { |
| 3029 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3030 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3031 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3032 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3033 | } |
| 3034 | } |
| 3035 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3036 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3037 | /** |
| 3038 | * @hide |
| 3039 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3040 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3041 | if (mService != null) { |
| 3042 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3043 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3044 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3045 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3049 | |
| 3050 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3051 | * @hide |
| 3052 | */ |
| 3053 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3054 | if (mService != null) { |
| 3055 | try { |
| 3056 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3057 | } catch (RemoteException e) { |
| 3058 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3059 | } |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | /** |
| 3064 | * @hide |
| 3065 | */ |
| 3066 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3067 | if (mService != null) { |
| 3068 | try { |
| 3069 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3070 | } catch (RemoteException e) { |
| 3071 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3072 | } |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3077 | * Should be called when keyguard has been dismissed. |
| 3078 | * @hide |
| 3079 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3080 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3081 | if (mService != null) { |
| 3082 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3083 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3084 | } catch (RemoteException e) { |
| 3085 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3086 | } |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | /** |
| 3091 | * Should be called when keyguard view has been shown to the user. |
| 3092 | * @hide |
| 3093 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3094 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3095 | if (mService != null) { |
| 3096 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3097 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3098 | } catch (RemoteException e) { |
| 3099 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3100 | } |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3105 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3106 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3107 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3108 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3109 | * @return whether the package was successfully registered as the device owner. |
| 3110 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3111 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3112 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3113 | public boolean setDeviceOwner(ComponentName who) { |
| 3114 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | /** |
| 3118 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3119 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3120 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3121 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | /** |
| 3125 | * @hide |
| 3126 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3127 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3128 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | /** |
| 3132 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3133 | * Sets the given package as the device owner. The package must already be installed. There |
| 3134 | * must not already be a device owner. |
| 3135 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3136 | * this method. |
| 3137 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3138 | * 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] | 3139 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3140 | * @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] | 3141 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3142 | * @return whether the package was successfully registered as the device owner. |
| 3143 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3144 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3145 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3146 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3147 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3148 | if (mService != null) { |
| 3149 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3150 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3151 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3152 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3153 | } |
| 3154 | } |
| 3155 | return false; |
| 3156 | } |
| 3157 | |
| 3158 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3159 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3160 | * 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] | 3161 | * 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] | 3162 | * package is currently registered as the device owner app, pass in the package name from |
| 3163 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3164 | * 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] | 3165 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3166 | * the setup process. |
| 3167 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3168 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3169 | * @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] | 3170 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3171 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3172 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3173 | } |
| 3174 | |
| 3175 | /** |
| 3176 | * @return true if a package is registered as device owner, only when it's running on the |
| 3177 | * calling user. |
| 3178 | * |
| 3179 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3180 | * @hide |
| 3181 | */ |
| 3182 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3183 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3184 | } |
| 3185 | |
| 3186 | /** |
| 3187 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3188 | * user. |
| 3189 | * |
| 3190 | * <p>Requires the MANAGE_USERS permission. |
| 3191 | * |
| 3192 | * @hide |
| 3193 | */ |
| 3194 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3195 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3196 | } |
| 3197 | |
| 3198 | /** |
| 3199 | * @return device owner component name, only when it's running on the calling user. |
| 3200 | * |
| 3201 | * @hide |
| 3202 | */ |
| 3203 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3204 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3205 | } |
| 3206 | |
| 3207 | /** |
| 3208 | * @return device owner component name, even if it's running on a different user. |
| 3209 | * |
| 3210 | * <p>Requires the MANAGE_USERS permission. |
| 3211 | * |
| 3212 | * @hide |
| 3213 | */ |
| 3214 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3215 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3216 | } |
| 3217 | |
| 3218 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3219 | if (packageName == null) { |
| 3220 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3221 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3222 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3223 | if (deviceOwner == null) { |
| 3224 | return false; |
| 3225 | } |
| 3226 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3229 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3230 | if (mService != null) { |
| 3231 | try { |
| 3232 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3233 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3234 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3235 | } |
| 3236 | } |
| 3237 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3240 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3241 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3242 | * no device owner. |
| 3243 | * |
| 3244 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3245 | * |
| 3246 | * @hide |
| 3247 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3248 | public int getDeviceOwnerUserId() { |
| 3249 | if (mService != null) { |
| 3250 | try { |
| 3251 | return mService.getDeviceOwnerUserId(); |
| 3252 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3253 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3254 | } |
| 3255 | } |
| 3256 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | /** |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3260 | * Clears the current device owner. The caller must be the device owner. |
| 3261 | * |
| 3262 | * This function should be used cautiously as once it is called it cannot |
| 3263 | * be undone. The device owner can only be set as a part of device setup |
| 3264 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3265 | * |
| 3266 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3267 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3268 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3269 | if (mService != null) { |
| 3270 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3271 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3272 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3273 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3278 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3279 | * Returns the device owner package name, only if it's running on the calling user. |
| 3280 | * |
| 3281 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3282 | * |
| 3283 | * @hide |
| 3284 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3285 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3286 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3287 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3288 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3292 | * @return true if the device is managed by any device owner. |
| 3293 | * |
| 3294 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3295 | * |
| 3296 | * @hide |
| 3297 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3298 | public boolean isDeviceManaged() { |
| 3299 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3300 | } |
| 3301 | |
| 3302 | /** |
| 3303 | * Returns the device owner name. Note this method *will* return the device owner |
| 3304 | * name when it's running on a different user. |
| 3305 | * |
| 3306 | * <p>Requires the MANAGE_USERS permission. |
| 3307 | * |
| 3308 | * @hide |
| 3309 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3310 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3311 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3312 | if (mService != null) { |
| 3313 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3314 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3315 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3316 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3317 | } |
| 3318 | } |
| 3319 | return null; |
| 3320 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3321 | |
| 3322 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3323 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3324 | * @deprecated Do not use |
| 3325 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3326 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3327 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3328 | @SystemApi |
| 3329 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3330 | return null; |
| 3331 | } |
| 3332 | |
| 3333 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3334 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3335 | * @deprecated Do not use |
| 3336 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3337 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3338 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3339 | @SystemApi |
| 3340 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3341 | return null; |
| 3342 | } |
| 3343 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3344 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3345 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3346 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3347 | * Sets the given component as an active admin and registers the package as the profile |
| 3348 | * owner for this user. The package must already be installed and there shouldn't be |
| 3349 | * an existing profile owner registered for this user. Also, this method must be called |
| 3350 | * before the user setup has been completed. |
| 3351 | * <p> |
| 3352 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3353 | * MANAGE_DEVICE_ADMINS permission. |
| 3354 | * @param admin The component to register as an active admin and profile owner. |
| 3355 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3356 | * @return whether the admin was successfully registered as the profile owner. |
| 3357 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3358 | * the user has already been set up. |
| 3359 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3360 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3361 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3362 | throws IllegalArgumentException { |
| 3363 | if (mService != null) { |
| 3364 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3365 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3366 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3367 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3368 | } catch (RemoteException re) { |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3369 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3370 | } |
| 3371 | } |
| 3372 | return false; |
| 3373 | } |
| 3374 | |
| 3375 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3376 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 3377 | * be from the same package as the active profile owner for this user, otherwise a |
| 3378 | * SecurityException will be thrown. |
| 3379 | * |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3380 | * <p>This doesn't work for managed profile owners. |
| 3381 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3382 | * @param admin The component to remove as the profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3383 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3384 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3385 | if (mService != null) { |
| 3386 | try { |
| 3387 | mService.clearProfileOwner(admin); |
| 3388 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3389 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3390 | } |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3395 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3396 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3397 | */ |
| 3398 | public boolean hasUserSetupCompleted() { |
| 3399 | if (mService != null) { |
| 3400 | try { |
| 3401 | return mService.hasUserSetupCompleted(); |
| 3402 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3403 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3404 | } |
| 3405 | } |
| 3406 | return true; |
| 3407 | } |
| 3408 | |
| 3409 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3410 | * @hide |
| 3411 | * 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] | 3412 | * already be installed. There must not already be a profile owner for this user. |
| 3413 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3414 | * this method. |
| 3415 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3416 | * - the caller is SYSTEM_UID. |
| 3417 | * - 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] | 3418 | * @param admin the component name to be registered as profile owner. |
| 3419 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3420 | * @param userHandle the userId to set the profile owner for. |
| 3421 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3422 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3423 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3424 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3425 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3426 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3427 | if (mService != null) { |
| 3428 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3429 | if (ownerName == null) { |
| 3430 | ownerName = ""; |
| 3431 | } |
| 3432 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3433 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3434 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3435 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 3436 | } |
| 3437 | } |
| 3438 | return false; |
| 3439 | } |
| 3440 | |
| 3441 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3442 | * Sets the device owner information to be shown on the lock screen. |
| 3443 | * |
| 3444 | * <p>If the device owner information is {@code null} or empty then the device owner info is |
| 3445 | * 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] | 3446 | * <p>If the device owner information contains only whitespaces then the message on the lock |
| 3447 | * 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] | 3448 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 3449 | * <p>If the device owner information needs to be localized, it is the responsibility of the |
| 3450 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3451 | * and set a new version of this string accordingly. |
| 3452 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3453 | * @param admin The name of the admin component to check. |
| 3454 | * @param info Device owner information which will be displayed instead of the user |
| 3455 | * owner info. |
| 3456 | * @return Whether the device owner information has been set. |
| 3457 | */ |
| 3458 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3459 | if (mService != null) { |
| 3460 | try { |
| 3461 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3462 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3463 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3464 | } |
| 3465 | } |
| 3466 | return false; |
| 3467 | } |
| 3468 | |
| 3469 | /** |
| 3470 | * @return The device owner information. If it is not set returns {@code null}. |
| 3471 | */ |
| 3472 | public String getDeviceOwnerLockScreenInfo() { |
| 3473 | if (mService != null) { |
| 3474 | try { |
| 3475 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3476 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3477 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3478 | } |
| 3479 | } |
| 3480 | return null; |
| 3481 | } |
| 3482 | |
| 3483 | /** |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3484 | * Called by device or profile owners for setting the package suspended for this user. |
| 3485 | * A suspended package will not be started by the package manager, its notifications will |
| 3486 | * be hidden and it will not show up in recents. The package must already be installed. |
| 3487 | * |
| 3488 | * @param admin The name of the admin component to check. |
| 3489 | * @param packageName The package name of the app to suspend or unsuspend. |
| 3490 | * @param suspended If set to {@code true} than the package will be suspended, if set to |
| 3491 | * {@code false} the package will be unsuspended. |
| 3492 | * @return boolean {@code true} if the operation was successfully performed, {@code false} |
| 3493 | * otherwise. |
| 3494 | */ |
| 3495 | public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName, |
| 3496 | boolean suspended) { |
| 3497 | if (mService != null) { |
| 3498 | try { |
| 3499 | return mService.setPackageSuspended(admin, packageName, suspended); |
| 3500 | } catch (RemoteException re) { |
| 3501 | Log.w(TAG, "Failed talking with device policy service", re); |
| 3502 | } |
| 3503 | } |
| 3504 | return false; |
| 3505 | } |
| 3506 | |
| 3507 | /** |
| 3508 | * Called by device or profile owners to determine if a package is suspended. |
| 3509 | * |
| 3510 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3511 | * @param packageName The name of the package to retrieve the suspended status of. |
| 3512 | * @return boolean {@code true} if the package is suspended, {@code false} otherwise. |
| 3513 | */ |
| 3514 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3515 | if (mService != null) { |
| 3516 | try { |
| 3517 | return mService.getPackageSuspended(admin, packageName); |
| 3518 | } catch (RemoteException e) { |
| 3519 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3520 | } |
| 3521 | } |
| 3522 | return false; |
| 3523 | } |
| 3524 | |
| 3525 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3526 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3527 | * be used. Only the profile owner can call this. |
| 3528 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3529 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3530 | * |
| 3531 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3532 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3533 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3534 | if (mService != null) { |
| 3535 | try { |
| 3536 | mService.setProfileEnabled(admin); |
| 3537 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3538 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3539 | } |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3544 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3545 | * 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] | 3546 | * never called by the profile or device owner, the name will be set to default values. |
| 3547 | * |
| 3548 | * @see #isProfileOwnerApp |
| 3549 | * @see #isDeviceOwnerApp |
| 3550 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3551 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3552 | * @param profileName The name of the profile. |
| 3553 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3554 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3555 | if (mService != null) { |
| 3556 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3557 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3558 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3559 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3560 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3561 | } |
| 3562 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3563 | |
| 3564 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3565 | * 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] | 3566 | * 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] | 3567 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3568 | * |
| 3569 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3570 | * @return Whether or not the package is registered as the profile owner. |
| 3571 | */ |
| 3572 | public boolean isProfileOwnerApp(String packageName) { |
| 3573 | if (mService != null) { |
| 3574 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 3575 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3576 | return profileOwner != null |
| 3577 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3578 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3579 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3580 | } |
| 3581 | } |
| 3582 | return false; |
| 3583 | } |
| 3584 | |
| 3585 | /** |
| 3586 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3587 | * @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] | 3588 | * owner has been set for that user. |
| 3589 | * @throws IllegalArgumentException if the userId is invalid. |
| 3590 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3591 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3592 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3593 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3594 | } |
| 3595 | |
| 3596 | /** |
| 3597 | * @see #getProfileOwner() |
| 3598 | * @hide |
| 3599 | */ |
| 3600 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3601 | if (mService != null) { |
| 3602 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3603 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3604 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3605 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3606 | throw new IllegalArgumentException( |
| 3607 | "Requested profile owner for invalid userId", re); |
| 3608 | } |
| 3609 | } |
| 3610 | return null; |
| 3611 | } |
| 3612 | |
| 3613 | /** |
| 3614 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3615 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3616 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3617 | * @throws IllegalArgumentException if the userId is invalid. |
| 3618 | */ |
| 3619 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3620 | if (mService != null) { |
| 3621 | try { |
| 3622 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3623 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3624 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3625 | throw new IllegalArgumentException( |
| 3626 | "Requested profile owner for invalid userId", re); |
| 3627 | } |
| 3628 | } |
| 3629 | return null; |
| 3630 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3631 | |
| 3632 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3633 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3634 | * @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] | 3635 | * @return the human readable name of the organisation associated with this profile owner or |
| 3636 | * null if one is not set. |
| 3637 | * @throws IllegalArgumentException if the userId is invalid. |
| 3638 | */ |
| 3639 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3640 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3641 | if (mService != null) { |
| 3642 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3643 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3644 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3645 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3646 | throw new IllegalArgumentException( |
| 3647 | "Requested profile owner for invalid userId", re); |
| 3648 | } |
| 3649 | } |
| 3650 | return null; |
| 3651 | } |
| 3652 | |
| 3653 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3654 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3655 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3656 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3657 | * the intent preferences are reset. |
| 3658 | * |
| 3659 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3660 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3661 | * intent handler for the filter. |
| 3662 | * |
| 3663 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3664 | * security exception will be thrown. |
| 3665 | * |
| 3666 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3667 | * @param filter The IntentFilter for which a default handler is added. |
| 3668 | * @param activity The Activity that is added as default intent handler. |
| 3669 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3670 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3671 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3672 | if (mService != null) { |
| 3673 | try { |
| 3674 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3675 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3676 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3677 | } |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | /** |
| 3682 | * 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] | 3683 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3684 | * |
| 3685 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3686 | * exception will be thrown. |
| 3687 | * |
| 3688 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3689 | * @param packageName The name of the package for which preferences are removed. |
| 3690 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3691 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3692 | String packageName) { |
| 3693 | if (mService != null) { |
| 3694 | try { |
| 3695 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3696 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3697 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3698 | } |
| 3699 | } |
| 3700 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3701 | |
| 3702 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3703 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 3704 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 3705 | * {@link #getApplicationRestrictions}. |
| 3706 | * <p> |
| 3707 | * This permission is persistent until it is later cleared by calling this method with a |
| 3708 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3709 | * <p> |
| 3710 | * The supplied application restriction managing package must be installed when calling this |
| 3711 | * API, otherwise an {@link IllegalArgumentException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3712 | * |
| 3713 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3714 | * @param packageName The package name which will be given access to application restrictions |
| 3715 | * APIs. If {@code null} is given the current package will be cleared. |
| 3716 | */ |
| 3717 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
| 3718 | @Nullable String packageName) { |
| 3719 | if (mService != null) { |
| 3720 | try { |
| 3721 | mService.setApplicationRestrictionsManagingPackage(admin, packageName); |
| 3722 | } catch (RemoteException e) { |
| 3723 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 3730 | * package for the current user, or {@code null} if none is set. |
| 3731 | * |
| 3732 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3733 | * @return The package name allowed to manage application restrictions on the current user, or |
| 3734 | * {@code null} if none is set. |
| 3735 | */ |
| 3736 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 3737 | if (mService != null) { |
| 3738 | try { |
| 3739 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 3740 | } catch (RemoteException e) { |
| 3741 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3742 | } |
| 3743 | } |
| 3744 | return null; |
| 3745 | } |
| 3746 | |
| 3747 | /** |
| 3748 | * Returns {@code true} if the calling package has been granted permission via |
| 3749 | * {@link #setApplicationRestrictionsManagingPackage} to manage application |
| 3750 | * restrictions for the calling user. |
| 3751 | */ |
| 3752 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 3753 | if (mService != null) { |
| 3754 | try { |
| 3755 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 3756 | } catch (RemoteException e) { |
| 3757 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3758 | } |
| 3759 | } |
| 3760 | return false; |
| 3761 | } |
| 3762 | |
| 3763 | /** |
| 3764 | * Sets the application restrictions for a given target application running in the calling user. |
| 3765 | * |
| 3766 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 3767 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 3768 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3769 | * |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 3770 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
| 3771 | * <ul> |
| 3772 | * <li>{@code boolean} |
| 3773 | * <li>{@code int} |
| 3774 | * <li>{@code String} or {@code String[]} |
| 3775 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 3776 | * </ul> |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3777 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3778 | * <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] | 3779 | * the caller can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3780 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 3781 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3782 | * <p>The application restrictions are only made visible to the target application via |
| 3783 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or |
| 3784 | * device owner, and the application restrictions managing package via |
| 3785 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3786 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3787 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3788 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3789 | * @param packageName The name of the package to update restricted settings for. |
| 3790 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 3791 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3792 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3793 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3794 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3795 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3796 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3797 | Bundle settings) { |
| 3798 | if (mService != null) { |
| 3799 | try { |
| 3800 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3801 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3802 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3808 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3809 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3810 | * trust agents but those enabled by this function call. If flag |
| 3811 | * {@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] | 3812 | * |
| 3813 | * <p>The calling device admin must have requested |
| 3814 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3815 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3816 | * |
| 3817 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3818 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3819 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3820 | * will be strictly disabled according to the state of the |
| 3821 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 3822 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 3823 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 3824 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
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 void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 3827 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3828 | if (mService != null) { |
| 3829 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3830 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3831 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3832 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3833 | } |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3838 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 3839 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 3840 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3841 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3842 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3843 | * this function returns a list of configurations for all admins that declare |
| 3844 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 3845 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 3846 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 3847 | * 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] | 3848 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3849 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3850 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3851 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3852 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3853 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3857 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3858 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3859 | if (mService != null) { |
| 3860 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3861 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3862 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3863 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3864 | } |
| 3865 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3866 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3870 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 3871 | * 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] | 3872 | * |
| 3873 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3874 | * security exception will be thrown. |
| 3875 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3876 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3877 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 3878 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3879 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3880 | if (mService != null) { |
| 3881 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3882 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3883 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3884 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3890 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 3891 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3892 | * |
| 3893 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3894 | * security exception will be thrown. |
| 3895 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3896 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3897 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3898 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3899 | if (mService != null) { |
| 3900 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3901 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3902 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3903 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3904 | } |
| 3905 | } |
| 3906 | return false; |
| 3907 | } |
| 3908 | |
| 3909 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3910 | * Determine whether or not caller-Id information has been disabled. |
| 3911 | * |
| 3912 | * @param userHandle The user for whom to check the caller-id permission |
| 3913 | * @hide |
| 3914 | */ |
| 3915 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 3916 | if (mService != null) { |
| 3917 | try { |
| 3918 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 3919 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3920 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3921 | } |
| 3922 | } |
| 3923 | return false; |
| 3924 | } |
| 3925 | |
| 3926 | /** |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 3927 | * Called by a profile owner of a managed profile to set whether contacts search from |
| 3928 | * the managed profile will be shown in the parent profile, for incoming calls. |
| 3929 | * |
| 3930 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3931 | * security exception will be thrown. |
| 3932 | * |
| 3933 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3934 | * @param disabled If true contacts search in the managed profile is not displayed. |
| 3935 | */ |
| 3936 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 3937 | boolean disabled) { |
| 3938 | if (mService != null) { |
| 3939 | try { |
| 3940 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 3941 | } catch (RemoteException e) { |
| 3942 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3943 | } |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | /** |
| 3948 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 3949 | * has been disabled. |
| 3950 | * |
| 3951 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3952 | * security exception will be thrown. |
| 3953 | * |
| 3954 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3955 | */ |
| 3956 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 3957 | if (mService != null) { |
| 3958 | try { |
| 3959 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 3960 | } catch (RemoteException e) { |
| 3961 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3962 | } |
| 3963 | } |
| 3964 | return false; |
| 3965 | } |
| 3966 | |
| 3967 | |
| 3968 | /** |
| 3969 | * Determine whether or not contacts search has been disabled. |
| 3970 | * |
| 3971 | * @param userHandle The user for whom to check the contacts search permission |
| 3972 | * @hide |
| 3973 | */ |
| 3974 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 3975 | if (mService != null) { |
| 3976 | try { |
| 3977 | return mService |
| 3978 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 3979 | } catch (RemoteException e) { |
| 3980 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 3981 | } |
| 3982 | } |
| 3983 | return false; |
| 3984 | } |
| 3985 | |
| 3986 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3987 | * 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] | 3988 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3989 | * @hide |
| 3990 | */ |
| 3991 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3992 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3993 | if (mService != null) { |
| 3994 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 3995 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 3996 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3997 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 3998 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3999 | } |
| 4000 | } |
| 4001 | } |
| 4002 | |
| 4003 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4004 | * 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] | 4005 | * @hide |
| 4006 | */ |
| 4007 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4008 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4009 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4010 | originalIntent); |
| 4011 | } |
| 4012 | |
| 4013 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4014 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 4015 | * devices can access enterprise contacts. |
| 4016 | * <p> |
| 4017 | * The calling device admin must be a profile owner. If it is not, a |
| 4018 | * security exception will be thrown. |
| 4019 | * <p> |
| 4020 | * This API works on managed profile only. |
| 4021 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4022 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4023 | * with. |
| 4024 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 4025 | * contacts. |
| 4026 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4027 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4028 | if (mService != null) { |
| 4029 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4030 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4031 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4032 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4033 | } |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | /** |
| 4038 | * Called by a profile owner of a managed profile to determine whether or |
| 4039 | * not Bluetooth devices cannot access enterprise contacts. |
| 4040 | * <p> |
| 4041 | * The calling device admin must be a profile owner. If it is not, a |
| 4042 | * security exception will be thrown. |
| 4043 | * <p> |
| 4044 | * This API works on managed profile only. |
| 4045 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4046 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4047 | * with. |
| 4048 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4049 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4050 | if (mService != null) { |
| 4051 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4052 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4053 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4054 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | return true; |
| 4058 | } |
| 4059 | |
| 4060 | /** |
| 4061 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4062 | * <p> |
| 4063 | * This API works on managed profile UserHandle only. |
| 4064 | * |
| 4065 | * @param userHandle The user for whom to check the caller-id permission |
| 4066 | * @hide |
| 4067 | */ |
| 4068 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4069 | if (mService != null) { |
| 4070 | try { |
| 4071 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4072 | .getIdentifier()); |
| 4073 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4074 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4075 | } |
| 4076 | } |
| 4077 | return true; |
| 4078 | } |
| 4079 | |
| 4080 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4081 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 4082 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4083 | * Only activity intents are supported. |
| 4084 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4085 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4086 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 4087 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4088 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 4089 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4090 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4091 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4092 | if (mService != null) { |
| 4093 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4094 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4095 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4096 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4097 | } |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4102 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4103 | * 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] | 4104 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4105 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4106 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4107 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4108 | if (mService != null) { |
| 4109 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4110 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4111 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4112 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4113 | } |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4118 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 4119 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4120 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 4121 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4122 | * By default the user can use any accessiblity service. When zero or more packages have |
| 4123 | * 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] | 4124 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4125 | * |
| 4126 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 4127 | * can be used, calling with an empty list only allows the builtin system's services. |
| 4128 | * |
| 4129 | * <p> System accesibility services are always available to the user the list can't modify |
| 4130 | * this. |
| 4131 | * |
| 4132 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4133 | * @param packageNames List of accessibility service package names. |
| 4134 | * |
| 4135 | * @return true if setting the restriction succeeded. It fail if there is |
| 4136 | * one or more non-system accessibility services enabled, that are not in the list. |
| 4137 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4138 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4139 | List<String> packageNames) { |
| 4140 | if (mService != null) { |
| 4141 | try { |
| 4142 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4143 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4144 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4145 | } |
| 4146 | } |
| 4147 | return false; |
| 4148 | } |
| 4149 | |
| 4150 | /** |
| 4151 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 4152 | * |
| 4153 | * <p>An empty list means no accessibility services except system services are allowed. |
| 4154 | * Null means all accessibility services are allowed. |
| 4155 | * |
| 4156 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4157 | * @return List of accessiblity service package names. |
| 4158 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4159 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4160 | if (mService != null) { |
| 4161 | try { |
| 4162 | return mService.getPermittedAccessibilityServices(admin); |
| 4163 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4164 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | return null; |
| 4168 | } |
| 4169 | |
| 4170 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4171 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4172 | * |
| 4173 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4174 | * @param packageName Accessibility service package name that needs to be checked. |
| 4175 | * @param userHandle user id the admin is running as. |
| 4176 | * @return true if the accessibility service is permitted, otherwise false. |
| 4177 | * |
| 4178 | * @hide |
| 4179 | */ |
| 4180 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4181 | @NonNull String packageName, int userHandle) { |
| 4182 | if (mService != null) { |
| 4183 | try { |
| 4184 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4185 | userHandle); |
| 4186 | } catch (RemoteException e) { |
| 4187 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4188 | } |
| 4189 | } |
| 4190 | return false; |
| 4191 | } |
| 4192 | |
| 4193 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4194 | * Returns the list of accessibility services permitted by the device or profiles |
| 4195 | * owners of this user. |
| 4196 | * |
| 4197 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4198 | * it will contain the intersection of the permitted lists for any device or profile |
| 4199 | * owners that apply to this user. It will also include any system accessibility services. |
| 4200 | * |
| 4201 | * @param userId which user to check for. |
| 4202 | * @return List of accessiblity service package names. |
| 4203 | * @hide |
| 4204 | */ |
| 4205 | @SystemApi |
| 4206 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4207 | if (mService != null) { |
| 4208 | try { |
| 4209 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4210 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4211 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4212 | } |
| 4213 | } |
| 4214 | return null; |
| 4215 | } |
| 4216 | |
| 4217 | /** |
| 4218 | * Called by a profile or device owner to set the permitted input methods services. When |
| 4219 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4220 | * user the device owner or profile owner is an admin for. |
| 4221 | * |
| 4222 | * By default the user can use any input method. When zero or more packages have |
| 4223 | * been added, input method that are not in the list and not part of the system |
| 4224 | * can not be enabled by the user. |
| 4225 | * |
| 4226 | * This method will fail if it is called for a admin that is not for the foreground user |
| 4227 | * or a profile of the foreground user. |
| 4228 | * |
| 4229 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 4230 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 4231 | * |
| 4232 | * <p> System input methods are always available to the user this method can't modify this. |
| 4233 | * |
| 4234 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4235 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 4236 | * @return true if setting the restriction succeeded. It will fail if there are |
| 4237 | * one or more non-system input methods currently enabled that are not in |
| 4238 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4240 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4241 | if (mService != null) { |
| 4242 | try { |
| 4243 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4244 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4245 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4246 | } |
| 4247 | } |
| 4248 | return false; |
| 4249 | } |
| 4250 | |
| 4251 | |
| 4252 | /** |
| 4253 | * Returns the list of permitted input methods set by this device or profile owner. |
| 4254 | * |
| 4255 | * <p>An empty list means no input methods except system input methods are allowed. |
| 4256 | * Null means all input methods are allowed. |
| 4257 | * |
| 4258 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4259 | * @return List of input method package names. |
| 4260 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4261 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4262 | if (mService != null) { |
| 4263 | try { |
| 4264 | return mService.getPermittedInputMethods(admin); |
| 4265 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4266 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4267 | } |
| 4268 | } |
| 4269 | return null; |
| 4270 | } |
| 4271 | |
| 4272 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4273 | * Called by the system to check if a specific input method is disabled by admin. |
| 4274 | * |
| 4275 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4276 | * @param packageName Input method package name that needs to be checked. |
| 4277 | * @param userHandle user id the admin is running as. |
| 4278 | * @return true if the input method is permitted, otherwise false. |
| 4279 | * |
| 4280 | * @hide |
| 4281 | */ |
| 4282 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4283 | @NonNull String packageName, int userHandle) { |
| 4284 | if (mService != null) { |
| 4285 | try { |
| 4286 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4287 | } catch (RemoteException e) { |
| 4288 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 4289 | } |
| 4290 | } |
| 4291 | return false; |
| 4292 | } |
| 4293 | |
| 4294 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4295 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4296 | * 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] | 4297 | * |
| 4298 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4299 | * it will contain the intersection of the permitted lists for any device or profile |
| 4300 | * owners that apply to this user. It will also include any system input methods. |
| 4301 | * |
| 4302 | * @return List of input method package names. |
| 4303 | * @hide |
| 4304 | */ |
| 4305 | @SystemApi |
| 4306 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4307 | if (mService != null) { |
| 4308 | try { |
| 4309 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4310 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4311 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4312 | } |
| 4313 | } |
| 4314 | return null; |
| 4315 | } |
| 4316 | |
| 4317 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4318 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4319 | * currently installed it. |
| 4320 | * |
| 4321 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4322 | * |
| 4323 | * @return List of package names to keep cached. |
| 4324 | * @hide |
| 4325 | */ |
| 4326 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4327 | if (mService != null) { |
| 4328 | try { |
| 4329 | return mService.getKeepUninstalledPackages(admin); |
| 4330 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4331 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4332 | } |
| 4333 | } |
| 4334 | return null; |
| 4335 | } |
| 4336 | |
| 4337 | /** |
| 4338 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4339 | * currently installed it. |
| 4340 | * |
| 4341 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4342 | * automatically pre-cached.</p> |
| 4343 | * |
| 4344 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4345 | * @param packageNames List of package names to keep cached. |
| 4346 | * @hide |
| 4347 | */ |
| 4348 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4349 | @NonNull List<String> packageNames) { |
| 4350 | if (mService != null) { |
| 4351 | try { |
| 4352 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4353 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4354 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4355 | } |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4360 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4361 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4362 | * created. If you need to persist an identifier for this user, use |
| 4363 | * {@link UserManager#getSerialNumberForUser}. |
| 4364 | * |
| 4365 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4366 | * @param name the user's name |
| 4367 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4368 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4369 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4370 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4371 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4372 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4373 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4374 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4375 | try { |
| 4376 | return mService.createUser(admin, name); |
| 4377 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4378 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4379 | } |
| 4380 | return null; |
| 4381 | } |
| 4382 | |
| 4383 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4384 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4385 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4386 | * created. If you need to persist an identifier for this user, use |
| 4387 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4388 | * immediately. |
| 4389 | * |
| 4390 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4391 | * as registered as an active admin on the new user. The profile owner package will be |
| 4392 | * installed on the new user if it already is installed on the device. |
| 4393 | * |
| 4394 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4395 | * profileOwnerComponent when onEnable is called. |
| 4396 | * |
| 4397 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4398 | * @param name the user's name |
| 4399 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4400 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4401 | * the user. |
| 4402 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4403 | * on the new user. |
| 4404 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4405 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4406 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4407 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4408 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4409 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4410 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4411 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4412 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4413 | try { |
| 4414 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 4415 | adminExtras); |
| 4416 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4417 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4418 | } |
| 4419 | return null; |
| 4420 | } |
| 4421 | |
| 4422 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4423 | * 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] | 4424 | */ |
| 4425 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4426 | |
| 4427 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4428 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4429 | * ephemeral. |
| 4430 | * @hide |
| 4431 | */ |
| 4432 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4433 | |
| 4434 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4435 | * Called by a device owner to create a user with the specified name and a given component of |
| 4436 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4437 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4438 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4439 | * user will not be started in the background. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4440 | * |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4441 | * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also |
| 4442 | * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and |
| 4443 | * will be registered as an active admin on the new user. The profile owner package will be |
| 4444 | * installed on the new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4445 | * |
| 4446 | * <p>If the adminExtras are not null, they will be stored on the device until the user is |
| 4447 | * started for the first time. Then the extras will be passed to the admin when |
| 4448 | * onEnable is called. |
| 4449 | * |
| 4450 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4451 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4452 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
| 4453 | * same package as admin, otherwise no user is created and an IllegalArgumentException is |
| 4454 | * thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4455 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
| 4456 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4457 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4458 | * @see UserHandle |
| 4459 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4460 | * user could not be created. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4461 | */ |
| 4462 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4463 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4464 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4465 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4466 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4467 | } catch (RemoteException re) { |
| 4468 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 4469 | } |
| 4470 | return null; |
| 4471 | } |
| 4472 | |
| 4473 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4474 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 4475 | * not be removed. |
| 4476 | * |
| 4477 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4478 | * @param userHandle the user to remove. |
| 4479 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 4480 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4481 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4482 | try { |
| 4483 | return mService.removeUser(admin, userHandle); |
| 4484 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4485 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4486 | return false; |
| 4487 | } |
| 4488 | } |
| 4489 | |
| 4490 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4491 | * Called by a device owner to switch the specified user to the foreground. |
| 4492 | * |
| 4493 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4494 | * @param userHandle the user to switch to; null will switch to primary. |
| 4495 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 4496 | * |
| 4497 | * @see Intent#ACTION_USER_FOREGROUND |
| 4498 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4499 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4500 | try { |
| 4501 | return mService.switchUser(admin, userHandle); |
| 4502 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4503 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4504 | return false; |
| 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4509 | * Retrieves the application restrictions for a given target application running in the calling |
| 4510 | * user. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4511 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4512 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4513 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4514 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4515 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4516 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4517 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4518 | * @param packageName The name of the package to fetch restricted settings of. |
| 4519 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 4520 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 4521 | * if no restrictions have been set. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4522 | * |
| 4523 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4524 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4525 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4526 | if (mService != null) { |
| 4527 | try { |
| 4528 | return mService.getApplicationRestrictions(admin, packageName); |
| 4529 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4530 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | return null; |
| 4534 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4535 | |
| 4536 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4537 | * 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] | 4538 | * <p> |
| 4539 | * The calling device admin must be a profile or device owner; if it is not, |
| 4540 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4541 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4542 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4543 | * with. |
| 4544 | * @param key The key of the restriction. See the constants in |
| 4545 | * {@link android.os.UserManager} for the list of keys. |
| 4546 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4547 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4548 | if (mService != null) { |
| 4549 | try { |
| 4550 | mService.setUserRestriction(admin, key, true); |
| 4551 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4552 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4553 | } |
| 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4558 | * 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] | 4559 | * <p> |
| 4560 | * The calling device admin must be a profile or device owner; if it is not, |
| 4561 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4562 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4563 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4564 | * with. |
| 4565 | * @param key The key of the restriction. See the constants in |
| 4566 | * {@link android.os.UserManager} for the list of keys. |
| 4567 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4568 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4569 | if (mService != null) { |
| 4570 | try { |
| 4571 | mService.setUserRestriction(admin, key, false); |
| 4572 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4573 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4574 | } |
| 4575 | } |
| 4576 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4577 | |
| 4578 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4579 | * Called by a profile or device owner to get user restrictions set with |
| 4580 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4581 | * <p> |
| 4582 | * The target user may have more restrictions set by the system or other device owner / profile |
| 4583 | * owner. To get all the user restrictions currently set, use |
| 4584 | * {@link UserManager#getUserRestrictions()}. |
| 4585 | * |
| 4586 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4587 | * @throws SecurityException if the {@code admin} is not an active admin. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4588 | */ |
| 4589 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4590 | return getUserRestrictions(admin, myUserId()); |
| 4591 | } |
| 4592 | |
| 4593 | /** @hide per-user version */ |
| 4594 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4595 | Bundle ret = null; |
| 4596 | if (mService != null) { |
| 4597 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4598 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4599 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4600 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4601 | } |
| 4602 | } |
| 4603 | return ret == null ? new Bundle() : ret; |
| 4604 | } |
| 4605 | |
| 4606 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4607 | * 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] | 4608 | * is unavailable for use, but the data and actual package file remain. |
| 4609 | * |
| 4610 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4611 | * @param packageName The name of the package to hide or unhide. |
| 4612 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 4613 | * unhidden. |
| 4614 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4615 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4616 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4617 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4618 | if (mService != null) { |
| 4619 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4620 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4621 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4622 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | return false; |
| 4626 | } |
| 4627 | |
| 4628 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4629 | * 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] | 4630 | * |
| 4631 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4632 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4633 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4634 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4635 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4636 | if (mService != null) { |
| 4637 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4638 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4639 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4640 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | return false; |
| 4644 | } |
| 4645 | |
| 4646 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4647 | * 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] | 4648 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4649 | * |
| 4650 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4651 | * @param packageName The package to be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4652 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4653 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4654 | if (mService != null) { |
| 4655 | try { |
| 4656 | mService.enableSystemApp(admin, packageName); |
| 4657 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4658 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4659 | } |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4664 | * 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] | 4665 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4666 | * |
| 4667 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4668 | * @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] | 4669 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4670 | * @return int The number of activities that matched the intent and were installed. |
| 4671 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4672 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4673 | if (mService != null) { |
| 4674 | try { |
| 4675 | return mService.enableSystemAppWithIntent(admin, intent); |
| 4676 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4677 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4678 | } |
| 4679 | } |
| 4680 | return 0; |
| 4681 | } |
| 4682 | |
| 4683 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4684 | * Called by a device owner or profile owner to disable account management for a specific type |
| 4685 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4686 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4687 | * <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] | 4688 | * security exception will be thrown. |
| 4689 | * |
| 4690 | * <p>When account management is disabled for an account type, adding or removing an account |
| 4691 | * of that type will not be possible. |
| 4692 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 4693 | * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
| 4694 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 4695 | * management for a specific type is disabled. |
| 4696 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4697 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4698 | * @param accountType For which account management is disabled or enabled. |
| 4699 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 4700 | * enabled (false). |
| 4701 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4702 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4703 | boolean disabled) { |
| 4704 | if (mService != null) { |
| 4705 | try { |
| 4706 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 4707 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4708 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4709 | } |
| 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4714 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 4715 | * |
| 4716 | * <p> Account management can be disabled/enabled by calling |
| 4717 | * {@link #setAccountManagementDisabled}. |
| 4718 | * |
| 4719 | * @return a list of account types for which account management has been disabled. |
| 4720 | * |
| 4721 | * @see #setAccountManagementDisabled |
| 4722 | */ |
| 4723 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4724 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | /** |
| 4728 | * @see #getAccountTypesWithManagementDisabled() |
| 4729 | * @hide |
| 4730 | */ |
| 4731 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4732 | if (mService != null) { |
| 4733 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4734 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4735 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4736 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4737 | } |
| 4738 | } |
| 4739 | |
| 4740 | return null; |
| 4741 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4742 | |
| 4743 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4744 | * Sets which packages may enter lock task mode. |
| 4745 | * |
| 4746 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 4747 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4748 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4749 | * 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] | 4750 | * package list results in locked tasks belonging to those packages to be finished. |
| 4751 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 4752 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4753 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4754 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4755 | * |
| 4756 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 4757 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 4758 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 4759 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4760 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4761 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4762 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4763 | if (mService != null) { |
| 4764 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4765 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4766 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4767 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4768 | } |
| 4769 | } |
| 4770 | } |
| 4771 | |
| 4772 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4773 | * 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] | 4774 | * |
| 4775 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4776 | * @hide |
| 4777 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4778 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4779 | if (mService != null) { |
| 4780 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4781 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4782 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4783 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4784 | } |
| 4785 | } |
| 4786 | return null; |
| 4787 | } |
| 4788 | |
| 4789 | /** |
| 4790 | * This function lets the caller know whether the given component is allowed to start the |
| 4791 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4792 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4793 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4794 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4795 | if (mService != null) { |
| 4796 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4797 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4798 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4799 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4800 | } |
| 4801 | } |
| 4802 | return false; |
| 4803 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4804 | |
| 4805 | /** |
| 4806 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 4807 | * 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] | 4808 | * <p>The settings that can be updated with this method are: |
| 4809 | * <ul> |
| 4810 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 4811 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 4812 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4813 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4814 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4815 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 4816 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4817 | * 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] | 4818 | * 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] | 4819 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4820 | * 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] | 4821 | * </li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4822 | * </ul> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4823 | * <p>Changing the following settings has no effect as of |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4824 | * {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 4825 | * <ul> |
| 4826 | * <li>{@link Settings.Global#BLUETOOTH_ON}. |
| 4827 | * Use {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 4828 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
| 4829 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 4830 | * <li>{@link Settings.Global#MODE_RINGER}. |
| 4831 | * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
| 4832 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 4833 | * <li>{@link Settings.Global#WIFI_ON}. |
| 4834 | * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
| 4835 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4836 | * |
| 4837 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4838 | * @param setting The name of the setting to update. |
| 4839 | * @param value The value to update the setting to. |
| 4840 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4841 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4842 | if (mService != null) { |
| 4843 | try { |
| 4844 | mService.setGlobalSetting(admin, setting, value); |
| 4845 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4846 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4847 | } |
| 4848 | } |
| 4849 | } |
| 4850 | |
| 4851 | /** |
| 4852 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 4853 | * that the value of the setting is in the correct form for the setting type should be performed |
| 4854 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4855 | * <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] | 4856 | * <ul> |
| 4857 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 4858 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 4859 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 4860 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 4861 | * <p>A device owner can additionally update the following settings: |
| 4862 | * <ul> |
| 4863 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 4864 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4865 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4866 | * @param setting The name of the setting to update. |
| 4867 | * @param value The value to update the setting to. |
| 4868 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4869 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4870 | if (mService != null) { |
| 4871 | try { |
| 4872 | mService.setSecureSetting(admin, setting, value); |
| 4873 | } catch (RemoteException e) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4874 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4875 | } |
| 4876 | } |
| 4877 | } |
| 4878 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4879 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4880 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4881 | * making permission requests of a local or remote administrator of the user. |
| 4882 | * <p/> |
| 4883 | * Only a profile owner can designate the restrictions provider. |
| 4884 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4885 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 4886 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4887 | * it removes the restrictions provider previously assigned. |
| 4888 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4889 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 4890 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4891 | if (mService != null) { |
| 4892 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4893 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4894 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4895 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4896 | } |
| 4897 | } |
| 4898 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4899 | |
| 4900 | /** |
| 4901 | * Called by profile or device owners to set the master volume mute on or off. |
| 4902 | * |
| 4903 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4904 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 4905 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4906 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4907 | if (mService != null) { |
| 4908 | try { |
| 4909 | mService.setMasterVolumeMuted(admin, on); |
| 4910 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4911 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4912 | } |
| 4913 | } |
| 4914 | } |
| 4915 | |
| 4916 | /** |
| 4917 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 4918 | * |
| 4919 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4920 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 4921 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4922 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4923 | if (mService != null) { |
| 4924 | try { |
| 4925 | return mService.isMasterVolumeMuted(admin); |
| 4926 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4927 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4928 | } |
| 4929 | } |
| 4930 | return false; |
| 4931 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4932 | |
| 4933 | /** |
| 4934 | * Called by profile or device owners to change whether a user can uninstall |
| 4935 | * a package. |
| 4936 | * |
| 4937 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4938 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4939 | * @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] | 4940 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4941 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4942 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4943 | if (mService != null) { |
| 4944 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4945 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4946 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4947 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4948 | } |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4953 | * 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] | 4954 | * 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] | 4955 | * <p> |
| 4956 | * <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] | 4957 | * 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] | 4958 | * 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] | 4959 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4960 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4961 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 4962 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4963 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 4964 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4965 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4966 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4967 | if (mService != null) { |
| 4968 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 4969 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4970 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4971 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4972 | } |
| 4973 | } |
| 4974 | return false; |
| 4975 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4976 | |
| 4977 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4978 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 4979 | * 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] | 4980 | * 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] | 4981 | * 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] | 4982 | * a package may have zero or more provider components, where each component |
| 4983 | * provides a different widget type. |
| 4984 | * <p> |
| 4985 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4986 | * |
| 4987 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4988 | * @param packageName The package from which widget providers are white-listed. |
| 4989 | * @return Whether the package was added. |
| 4990 | * |
| 4991 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4992 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4993 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4994 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4995 | if (mService != null) { |
| 4996 | try { |
| 4997 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 4998 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 4999 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5000 | } |
| 5001 | } |
| 5002 | return false; |
| 5003 | } |
| 5004 | |
| 5005 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5006 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 5007 | * 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] | 5008 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 5009 | * android.content.ComponentName, String)}. |
| 5010 | * <p> |
| 5011 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5012 | * |
| 5013 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5014 | * @param packageName The package from which widget providers are no longer |
| 5015 | * white-listed. |
| 5016 | * @return Whether the package was removed. |
| 5017 | * |
| 5018 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5019 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5020 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5021 | public boolean removeCrossProfileWidgetProvider( |
| 5022 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5023 | if (mService != null) { |
| 5024 | try { |
| 5025 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5026 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5027 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5028 | } |
| 5029 | } |
| 5030 | return false; |
| 5031 | } |
| 5032 | |
| 5033 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5034 | * 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] | 5035 | * available in the parent profile. |
| 5036 | * |
| 5037 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5038 | * @return The white-listed package list. |
| 5039 | * |
| 5040 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5041 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5042 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5043 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5044 | if (mService != null) { |
| 5045 | try { |
| 5046 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5047 | if (providers != null) { |
| 5048 | return providers; |
| 5049 | } |
| 5050 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5051 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5052 | } |
| 5053 | } |
| 5054 | return Collections.emptyList(); |
| 5055 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5056 | |
| 5057 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5058 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5059 | * |
| 5060 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5061 | * @param icon the bitmap to set as the photo. |
| 5062 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5063 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5064 | try { |
| 5065 | mService.setUserIcon(admin, icon); |
| 5066 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5067 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5068 | } |
| 5069 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5070 | |
| 5071 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5072 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5073 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5074 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5075 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 5076 | * components in the device owner package can set system update policies and the |
| 5077 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5078 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5079 | * @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] | 5080 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5081 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5082 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5083 | if (mService != null) { |
| 5084 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5085 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5086 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5087 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5088 | } |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5093 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5094 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5095 | * @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] | 5096 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5097 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5098 | if (mService != null) { |
| 5099 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5100 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5101 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5102 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5103 | } |
| 5104 | } |
| 5105 | return null; |
| 5106 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5107 | |
| 5108 | /** |
| 5109 | * Called by a device owner to disable the keyguard altogether. |
| 5110 | * |
| 5111 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 5112 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 5113 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 5114 | * being disabled. |
| 5115 | * |
| 5116 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5117 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5118 | * |
| 5119 | * @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] | 5120 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5121 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5122 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5123 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5124 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5125 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5126 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5127 | return false; |
| 5128 | } |
| 5129 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5130 | |
| 5131 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5132 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 5133 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5134 | * a single use device. |
| 5135 | * |
| 5136 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5137 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 5138 | * |
| 5139 | * @return {@code false} if attempting to disable the status bar failed. |
| 5140 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5141 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5142 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5143 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5144 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5145 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5146 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5147 | return false; |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5148 | } |
| 5149 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5150 | |
| 5151 | /** |
| 5152 | * Callable by the system update service to notify device owners about pending updates. |
| 5153 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5154 | * permission. |
| 5155 | * |
| 5156 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5157 | * when the current pending update was first available. -1 if no update is available. |
| 5158 | * @hide |
| 5159 | */ |
| 5160 | @SystemApi |
| 5161 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5162 | if (mService != null) { |
| 5163 | try { |
| 5164 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5165 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5166 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5167 | } |
| 5168 | } |
| 5169 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5170 | |
| 5171 | /** |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5172 | * Called by profile or device owners to set the default response for future runtime permission |
| 5173 | * requests by applications. The policy can allow for normal operation which prompts the |
| 5174 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 5175 | * 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] | 5176 | * updates. When a permission is denied or granted this way, the effect is equivalent to setting |
| 5177 | * the permission grant state via {@link #setPermissionGrantState}. |
| 5178 | * |
| 5179 | * <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] | 5180 | * 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] | 5181 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5182 | * @param admin Which profile or device owner this request is associated with. |
| 5183 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 5184 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5185 | * |
| 5186 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5187 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5188 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5189 | try { |
| 5190 | mService.setPermissionPolicy(admin, policy); |
| 5191 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5192 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5193 | } |
| 5194 | } |
| 5195 | |
| 5196 | /** |
| 5197 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5198 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5199 | * @param admin Which profile or device owner this request is associated with. |
| 5200 | * @return the current policy for future permission requests. |
| 5201 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5202 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5203 | try { |
| 5204 | return mService.getPermissionPolicy(admin); |
| 5205 | } catch (RemoteException re) { |
| 5206 | return PERMISSION_POLICY_PROMPT; |
| 5207 | } |
| 5208 | } |
| 5209 | |
| 5210 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5211 | * Sets the grant state of a runtime permission for a specific application. The state |
| 5212 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 5213 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 5214 | * is denied and the user cannot manage it through the UI, and {@link |
| 5215 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 5216 | * user cannot manage it through the UI. This might affect all permissions in a |
| 5217 | * group that the runtime permission belongs to. This method can only be called |
| 5218 | * by a profile or device owner. |
| 5219 | * |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5220 | * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not |
| 5221 | * revoke the permission. It retains the previous grant, if any. |
| 5222 | * |
| 5223 | * <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] | 5224 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5225 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5226 | * @param admin Which profile or device owner this request is associated with. |
| 5227 | * @param packageName The application to grant or revoke a permission to. |
| 5228 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5229 | * @param grantState The permission grant state which is one of {@link |
| 5230 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5231 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5232 | * @return whether the permission was successfully granted or revoked. |
| 5233 | * |
| 5234 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5235 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5236 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5237 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5238 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5239 | String permission, int grantState) { |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5240 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5241 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5242 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5243 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5244 | return false; |
| 5245 | } |
| 5246 | } |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5247 | |
| 5248 | /** |
| 5249 | * Returns the current grant state of a runtime permission for a specific application. |
| 5250 | * |
| 5251 | * @param admin Which profile or device owner this request is associated with. |
| 5252 | * @param packageName The application to check the grant state for. |
| 5253 | * @param permission The permission to check for. |
| 5254 | * @return the current grant state specified by device policy. If the profile or device owner |
| 5255 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 5256 | * This does not indicate whether or not the permission is currently granted for the package. |
| 5257 | * |
| 5258 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 5259 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5260 | * which indicates if the permission is currently denied or granted. |
| 5261 | * |
| 5262 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5263 | * @see PackageManager#checkPermission(String, String) |
| 5264 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5265 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5266 | String permission) { |
| 5267 | try { |
| 5268 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5269 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5270 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5271 | return PERMISSION_GRANT_STATE_DEFAULT; |
| 5272 | } |
| 5273 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5274 | |
| 5275 | /** |
| 5276 | * Returns if provisioning a managed profile or device is possible or not. |
| 5277 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5278 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 5279 | * Note that even if this method returns true, there is a slight possibility that the |
| 5280 | * provisioning will not be allowed when it is actually initiated because some event has |
| 5281 | * happened in between. |
| 5282 | * @return if provisioning a managed profile or device is possible or not. |
| 5283 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5284 | */ |
| 5285 | public boolean isProvisioningAllowed(String action) { |
| 5286 | try { |
| 5287 | return mService.isProvisioningAllowed(action); |
| 5288 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5289 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5290 | return false; |
| 5291 | } |
| 5292 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5293 | |
| 5294 | /** |
| 5295 | * @hide |
| 5296 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5297 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5298 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5299 | * @param admin Which profile owner this request is associated with. |
| 5300 | * @return if this user is a managed profile of another user. |
| 5301 | */ |
| 5302 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5303 | try { |
| 5304 | return mService.isManagedProfile(admin); |
| 5305 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5306 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5307 | return false; |
| 5308 | } |
| 5309 | } |
| 5310 | |
| 5311 | /** |
| 5312 | * @hide |
| 5313 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5314 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5315 | * @param admin Which device owner this request is associated with. |
| 5316 | * @return if this user is a system-only user. |
| 5317 | */ |
| 5318 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5319 | try { |
| 5320 | return mService.isSystemOnlyUser(admin); |
| 5321 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5322 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5323 | return false; |
| 5324 | } |
| 5325 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5326 | |
| 5327 | /** |
| 5328 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5329 | * |
| 5330 | * @return the MAC address of the Wi-Fi device, or null when the information is not |
| 5331 | * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5332 | * |
| 5333 | * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5334 | */ |
| 5335 | public String getWifiMacAddress() { |
| 5336 | try { |
| 5337 | return mService.getWifiMacAddress(); |
| 5338 | } catch (RemoteException re) { |
Makoto Onuki | 55c46f2 | 2015-11-25 14:56:23 -0800 | [diff] [blame] | 5339 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5340 | return null; |
| 5341 | } |
| 5342 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5343 | |
| 5344 | /** |
| 5345 | * Called by device owner to reboot the device. |
| 5346 | */ |
| 5347 | public void reboot(@NonNull ComponentName admin) { |
| 5348 | try { |
| 5349 | mService.reboot(admin); |
| 5350 | } catch (RemoteException re) { |
| 5351 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5352 | } |
| 5353 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5354 | |
| 5355 | /** |
| 5356 | * Called by a device admin to set the short support message. This will |
| 5357 | * be displayed to the user in settings screens where funtionality has |
| 5358 | * been disabled by the admin. |
| 5359 | * |
| 5360 | * The message should be limited to a short statement such as |
| 5361 | * "This setting is disabled by your administrator. Contact someone@example.com |
| 5362 | * for support." |
| 5363 | * If the message is longer than 200 characters it may be truncated. |
| 5364 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5365 | * <p>If the short support message needs to be localized, it is the responsibility of the |
| 5366 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5367 | * and set a new version of this string accordingly. |
| 5368 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5369 | * @see #setLongSupportMessage |
| 5370 | * |
| 5371 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5372 | * @param message Short message to be displayed to the user in settings or null to |
| 5373 | * clear the existing message. |
| 5374 | */ |
| 5375 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5376 | @Nullable String message) { |
| 5377 | if (mService != null) { |
| 5378 | try { |
| 5379 | mService.setShortSupportMessage(admin, message); |
| 5380 | } catch (RemoteException e) { |
| 5381 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5382 | } |
| 5383 | } |
| 5384 | } |
| 5385 | |
| 5386 | /** |
| 5387 | * Called by a device admin to get the short support message. |
| 5388 | * |
| 5389 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5390 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5391 | * or null if no message has been set. |
| 5392 | */ |
| 5393 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5394 | if (mService != null) { |
| 5395 | try { |
| 5396 | return mService.getShortSupportMessage(admin); |
| 5397 | } catch (RemoteException e) { |
| 5398 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5399 | } |
| 5400 | } |
| 5401 | return null; |
| 5402 | } |
| 5403 | |
| 5404 | /** |
| 5405 | * Called by a device admin to set the long support message. This will |
| 5406 | * be displayed to the user in the device administators settings screen. |
| 5407 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5408 | * <p>If the long support message needs to be localized, it is the responsibility of the |
| 5409 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5410 | * and set a new version of this string accordingly. |
| 5411 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5412 | * @see #setShortSupportMessage |
| 5413 | * |
| 5414 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5415 | * @param message Long message to be displayed to the user in settings or null to |
| 5416 | * clear the existing message. |
| 5417 | */ |
| 5418 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5419 | @Nullable String message) { |
| 5420 | if (mService != null) { |
| 5421 | try { |
| 5422 | mService.setLongSupportMessage(admin, message); |
| 5423 | } catch (RemoteException e) { |
| 5424 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5425 | } |
| 5426 | } |
| 5427 | } |
| 5428 | |
| 5429 | /** |
| 5430 | * Called by a device admin to get the long support message. |
| 5431 | * |
| 5432 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5433 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5434 | * or null if no message has been set. |
| 5435 | */ |
| 5436 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5437 | if (mService != null) { |
| 5438 | try { |
| 5439 | return mService.getLongSupportMessage(admin); |
| 5440 | } catch (RemoteException e) { |
| 5441 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5442 | } |
| 5443 | } |
| 5444 | return null; |
| 5445 | } |
| 5446 | |
| 5447 | /** |
| 5448 | * Called by the system to get the short support message. |
| 5449 | * |
| 5450 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5451 | * @param userHandle user id the admin is running as. |
| 5452 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5453 | * |
| 5454 | * @hide |
| 5455 | */ |
| 5456 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5457 | if (mService != null) { |
| 5458 | try { |
| 5459 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5460 | } catch (RemoteException e) { |
| 5461 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5462 | } |
| 5463 | } |
| 5464 | return null; |
| 5465 | } |
| 5466 | |
| 5467 | |
| 5468 | /** |
| 5469 | * Called by the system to get the long support message. |
| 5470 | * |
| 5471 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5472 | * @param userHandle user id the admin is running as. |
| 5473 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5474 | * |
| 5475 | * @hide |
| 5476 | */ |
| 5477 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5478 | if (mService != null) { |
| 5479 | try { |
| 5480 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5481 | } catch (RemoteException e) { |
| 5482 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5483 | } |
| 5484 | } |
| 5485 | return null; |
| 5486 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5487 | |
| 5488 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5489 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5490 | * whose calls act on the parent profile. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5491 | * |
| 5492 | * <p> Note only some methods will work on the parent Manager. |
| 5493 | * |
| 5494 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
| 5495 | */ |
| 5496 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5497 | try { |
| 5498 | if (!mService.isManagedProfile(admin)) { |
| 5499 | throw new SecurityException("The current user does not have a parent profile."); |
| 5500 | } |
| 5501 | return new DevicePolicyManager(mContext, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5502 | } catch (RemoteException e) { |
| 5503 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5504 | return null; |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | /** |
| 5509 | * Called by device owner to control the device logging feature. Logging can only be |
| 5510 | * enabled on single user devices where the sole user is managed by the device owner. |
| 5511 | * |
| 5512 | * <p> Device logs contain various information intended for security auditing purposes. |
| 5513 | * See {@link SecurityEvent} for details. |
| 5514 | * |
| 5515 | * @param admin Which device owner this request is associated with. |
| 5516 | * @param enabled whether device logging should be enabled or not. |
| 5517 | * @see #retrieveDeviceLogs |
| 5518 | */ |
| 5519 | public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 5520 | try { |
| 5521 | mService.setDeviceLoggingEnabled(admin, enabled); |
| 5522 | } catch (RemoteException re) { |
| 5523 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | /** |
| 5528 | * Return whether device logging is enabled or not by the device owner. |
| 5529 | * |
| 5530 | * @param admin Which device owner this request is associated with. |
| 5531 | * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise. |
| 5532 | */ |
| 5533 | public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) { |
| 5534 | try { |
| 5535 | return mService.getDeviceLoggingEnabled(admin); |
| 5536 | } catch (RemoteException re) { |
| 5537 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5538 | return false; |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | /** |
| 5543 | * Called by device owner to retrieve all new device logging entries since the last call to |
| 5544 | * this API after device boots. |
| 5545 | * |
| 5546 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 5547 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 5548 | * |
| 5549 | * @param admin Which device owner this request is associated with. |
| 5550 | * @return the new batch of device logs which is a list of {@link SecurityEvent}, |
| 5551 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
| 5552 | */ |
| 5553 | public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) { |
| 5554 | try { |
| 5555 | ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin); |
| 5556 | if (list != null) { |
| 5557 | return list.getList(); |
| 5558 | } else { |
| 5559 | // Rate limit exceeded. |
| 5560 | return null; |
| 5561 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5562 | } catch (RemoteException re) { |
| 5563 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5564 | return null; |
| 5565 | } |
| 5566 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5567 | |
| 5568 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 5569 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 5570 | * profile. |
| 5571 | * |
| 5572 | * @hide |
| 5573 | */ |
| 5574 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 5575 | mContext.checkSelfPermission( |
| 5576 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 5577 | if (!uInfo.isManagedProfile()) { |
| 5578 | throw new SecurityException("The user " + uInfo.id |
| 5579 | + " does not have a parent profile."); |
| 5580 | } |
| 5581 | return new DevicePolicyManager(mContext, true); |
| 5582 | } |
| 5583 | |
| 5584 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5585 | * Called by device owners to retrieve device logs from before the device's last reboot. |
| 5586 | * |
| 5587 | * <p> |
| 5588 | * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be |
| 5589 | * corruption-free during power cycles, due to hardware variations and limitations. As a |
| 5590 | * result, this API is provided as best-effort and the returned logs may contain corrupted data. |
| 5591 | * </strong> |
| 5592 | * |
| 5593 | * @param admin Which device owner this request is associated with. |
| 5594 | * @return Device logs from before the latest reboot of the system. |
| 5595 | */ |
| 5596 | public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) { |
| 5597 | try { |
| 5598 | ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin); |
| 5599 | return list.getList(); |
| 5600 | } catch (RemoteException re) { |
| 5601 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5602 | return Collections.<SecurityEvent>emptyList(); |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5607 | * Called by a profile owner of a managed profile to set the color used for customization. |
| 5608 | * This color is used as background color of the confirm credentials screen for that user. |
| 5609 | * The default color is {@link android.graphics.Color#GRAY}. |
| 5610 | * |
| 5611 | * <p>The confirm credentials screen can be created using |
| 5612 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5613 | * |
| 5614 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5615 | * @param color The 32bit representation of the color to be used. |
| 5616 | */ |
| 5617 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5618 | try { |
| 5619 | mService.setOrganizationColor(admin, color); |
| 5620 | } catch (RemoteException re) { |
| 5621 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 5626 | * @hide |
| 5627 | * |
| 5628 | * Sets the color used for customization. |
| 5629 | * |
| 5630 | * @param color The 32bit representation of the color to be used. |
| 5631 | * @param userId which user to set the color to. |
| 5632 | * @RequiresPermission(allOf = { |
| 5633 | * Manifest.permission.MANAGE_USERS, |
| 5634 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 5635 | */ |
| 5636 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 5637 | try { |
| 5638 | mService.setOrganizationColorForUser(color, userId); |
| 5639 | } catch (RemoteException re) { |
| 5640 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5641 | } |
| 5642 | } |
| 5643 | |
| 5644 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5645 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5646 | * This color is used as background color of the confirm credentials screen for that user. |
| 5647 | * |
| 5648 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5649 | * @return The 32bit representation of the color to be used. |
| 5650 | */ |
| 5651 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 5652 | try { |
| 5653 | return mService.getOrganizationColor(admin); |
| 5654 | } catch (RemoteException re) { |
| 5655 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5656 | return 0; |
| 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | /** |
| 5661 | * @hide |
| 5662 | * Retrieve the customization color for a given user. |
| 5663 | * |
| 5664 | * @param userHandle The user id of the user we're interested in. |
| 5665 | * @return The 32bit representation of the color to be used. |
| 5666 | */ |
| 5667 | public int getOrganizationColorForUser(int userHandle) { |
| 5668 | try { |
| 5669 | return mService.getOrganizationColorForUser(userHandle); |
| 5670 | } catch (RemoteException re) { |
| 5671 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5672 | return 0; |
| 5673 | } |
| 5674 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5675 | |
| 5676 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5677 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 5678 | * management. |
| 5679 | * |
| 5680 | * <p>If the organization name needs to be localized, it is the responsibility of the |
| 5681 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5682 | * and set a new version of this string accordingly. |
| 5683 | * |
| 5684 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5685 | * @param title The organization name or {@code null} to clear a previously set name. |
| 5686 | */ |
| 5687 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 5688 | try { |
| 5689 | mService.setOrganizationName(admin, title); |
| 5690 | } catch (RemoteException re) { |
| 5691 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5692 | } |
| 5693 | } |
| 5694 | |
| 5695 | /** |
| 5696 | * Called by a profile owner of a managed profile to retrieve the name of the organization |
| 5697 | * under management. |
| 5698 | * |
| 5699 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5700 | * @return The organization name or {@code null} if none is set. |
| 5701 | */ |
| 5702 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 5703 | try { |
| 5704 | return mService.getOrganizationName(admin); |
| 5705 | } catch (RemoteException re) { |
| 5706 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5707 | return null; |
| 5708 | } |
| 5709 | } |
| 5710 | |
| 5711 | /** |
| 5712 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 5713 | * |
| 5714 | * @param userHandle The user id of the user we're interested in. |
| 5715 | * @return The organization name or {@code null} if none is set. |
| 5716 | * |
| 5717 | * @hide |
| 5718 | */ |
| 5719 | public String getOrganizationNameForUser(int userHandle) { |
| 5720 | try { |
| 5721 | return mService.getOrganizationNameForUser(userHandle); |
| 5722 | } catch (RemoteException re) { |
| 5723 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE); |
| 5724 | return null; |
| 5725 | } |
| 5726 | } |
| 5727 | |
| 5728 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5729 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 5730 | * return {@link #STATE_USER_UNMANAGED} |
| 5731 | * @hide |
| 5732 | */ |
| 5733 | @UserProvisioningState |
| 5734 | public int getUserProvisioningState() { |
| 5735 | if (mService != null) { |
| 5736 | try { |
| 5737 | return mService.getUserProvisioningState(); |
| 5738 | } catch (RemoteException e) { |
| 5739 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5740 | } |
| 5741 | } |
| 5742 | return STATE_USER_UNMANAGED; |
| 5743 | } |
| 5744 | |
| 5745 | /** |
| 5746 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 5747 | * |
| 5748 | * @param state to store |
| 5749 | * @param userHandle for user |
| 5750 | * @hide |
| 5751 | */ |
| 5752 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 5753 | if (mService != null) { |
| 5754 | try { |
| 5755 | mService.setUserProvisioningState(state, userHandle); |
| 5756 | } catch (RemoteException e) { |
| 5757 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e); |
| 5758 | } |
| 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5763 | * @hide |
| 5764 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 5765 | * affiliated if it is managed by the same entity as the device. |
| 5766 | * |
| 5767 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 5768 | * user/profile is considered affiliated if the following conditions are both met: |
| 5769 | * <ul> |
| 5770 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 5771 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 5772 | * and a profile owner intersect, they must have come from the same source, which means that |
| 5773 | * the device owner and profile owner are controlled by the same entity.</li> |
| 5774 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 5775 | * </ul> |
| 5776 | * |
| 5777 | * @param admin Which profile or device owner this request is associated with. |
| 5778 | * @param ids A set of opaque affiliation ids. |
| 5779 | */ |
| 5780 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 5781 | try { |
| 5782 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 5783 | } catch (RemoteException e) { |
| 5784 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | /** |
| 5789 | * @hide |
| 5790 | * Returns whether this user/profile is affiliated with the device. See |
| 5791 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 5792 | * |
| 5793 | * @return whether this user/profile is affiliated with the device. |
| 5794 | */ |
| 5795 | public boolean isAffiliatedUser() { |
| 5796 | try { |
| 5797 | return mService != null && mService.isAffiliatedUser(); |
| 5798 | } catch (RemoteException e) { |
| 5799 | Log.w(TAG, "Failed talking with device policy service", e); |
| 5800 | return false; |
| 5801 | } |
| 5802 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 5803 | |
| 5804 | /** |
| 5805 | * @hide |
| 5806 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 5807 | * to be started |
| 5808 | * @param packageName the package to check for |
| 5809 | * @return whether the uninstall intent for {@code packageName} is pending |
| 5810 | */ |
| 5811 | public boolean isUninstallInQueue(String packageName) { |
| 5812 | try { |
| 5813 | return mService.isUninstallInQueue(packageName); |
| 5814 | } catch (RemoteException re) { |
| 5815 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5816 | return false; |
| 5817 | } |
| 5818 | } |
| 5819 | |
| 5820 | /** |
| 5821 | * @hide |
| 5822 | * @param packageName the package containing active DAs to be uninstalled |
| 5823 | */ |
| 5824 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 5825 | try { |
| 5826 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 5827 | } catch (RemoteException re) { |
| 5828 | Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re); |
| 5829 | } |
| 5830 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 5831 | } |