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 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 103 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 104 | this(context, |
| 105 | IDevicePolicyManager.Stub.asInterface( |
| 106 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 107 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 110 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 111 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 112 | protected DevicePolicyManager( |
| 113 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 114 | mContext = context; |
| 115 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 116 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** @hide */ |
| 120 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 121 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 122 | return me.mService != null ? me : null; |
| 123 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 124 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 125 | /** @hide test will override it. */ |
| 126 | @VisibleForTesting |
| 127 | protected int myUserId() { |
| 128 | return UserHandle.myUserId(); |
| 129 | } |
| 130 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 131 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 132 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 133 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 134 | * <p>A managed profile allows data separation for example for the usage of a |
| 135 | * device as a personal and corporate device. The user which provisioning is started from and |
| 136 | * the managed profile share a launcher. |
| 137 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 138 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 139 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 140 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 141 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 142 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 143 | * {@link #isProvisioningAllowed(String)}. |
| 144 | * |
| 145 | * <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] | 146 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 147 | * 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] | 148 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 149 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 150 | * |
| 151 | * <p> The intent may also contain the following extras: |
| 152 | * <ul> |
| 153 | * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li> |
| 154 | * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li> |
| 155 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 156 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 157 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 158 | * in the provisioning intent. The |
| 159 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 160 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 161 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 162 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 163 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 164 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 165 | * |
| 166 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 167 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 168 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 169 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 170 | * 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] | 171 | */ |
| 172 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 173 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 174 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 175 | |
| 176 | /** |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 177 | * @hide |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 178 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 179 | * |
| 180 | * <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] | 181 | * 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] | 182 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 183 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 184 | * allowed. |
| 185 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 186 | * <p>This intent should contain the extra |
| 187 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 188 | * |
| 189 | * <p> If provisioning fails, the device returns to its previous state. |
| 190 | * |
| 191 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 192 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 193 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 194 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 195 | * 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] | 196 | */ |
| 197 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 198 | public static final String ACTION_PROVISION_MANAGED_USER |
| 199 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 200 | |
| 201 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 202 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 203 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 204 | * |
| 205 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 206 | * A device owner has full control over the device. The device owner can not be modified by the |
| 207 | * user. |
| 208 | * |
| 209 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 210 | * employee or client. |
| 211 | * |
| 212 | * <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] | 213 | * It is possible to check if provisioning is allowed or not by querying the method |
| 214 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 215 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 216 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 217 | * <ul> |
| 218 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 219 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 220 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 221 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 222 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 223 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 224 | * </ul> |
| 225 | * |
| 226 | * <p> When device owner provisioning has completed, an intent of the type |
| 227 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 228 | * device owner. |
| 229 | * |
| 230 | * <p> If provisioning fails, the device is factory reset. |
| 231 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 232 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 233 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 234 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 235 | * 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] | 236 | */ |
| 237 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 238 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 239 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 240 | |
| 241 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 242 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 243 | * |
| 244 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 245 | * the device. A device owner has full control over the device. The device owner can not be |
| 246 | * modified by the user and the only way of resetting the device is via factory reset. |
| 247 | * |
| 248 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 249 | * employee or client. |
| 250 | * |
| 251 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 252 | * |
| 253 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 254 | * by a privileged app with the permission |
| 255 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 256 | * |
| 257 | * <p>The provisioning intent contains the following properties: |
| 258 | * <ul> |
| 259 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 260 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 261 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 262 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 275 | * |
| 276 | * @hide |
| 277 | */ |
| 278 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 279 | @SystemApi |
| 280 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 281 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 282 | |
| 283 | /** |
| 284 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 285 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 286 | * |
| 287 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 288 | * management state that is distinct from that reached by |
| 289 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 290 | * user, and only has control over device-wide policies, not individual users and their data. |
| 291 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 292 | * this form of device management. |
| 293 | * |
| 294 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 295 | * A device owner has full control over the device. The device owner can not be modified by the |
| 296 | * user. |
| 297 | * |
| 298 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 299 | * employee or client. |
| 300 | * |
| 301 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 302 | * It is possible to check if provisioning is allowed or not by querying the method |
| 303 | * {@link #isProvisioningAllowed(String)}. |
| 304 | * |
| 305 | * <p>The intent contains the following extras: |
| 306 | * <ul> |
| 307 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 308 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 309 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 310 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 311 | * </ul> |
| 312 | * |
| 313 | * <p> When device owner provisioning has completed, an intent of the type |
| 314 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 315 | * device owner. |
| 316 | * |
| 317 | * <p> If provisioning fails, the device is factory reset. |
| 318 | * |
| 319 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 320 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 321 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 322 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 323 | * |
| 324 | * @hide |
| 325 | */ |
| 326 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 327 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 328 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 329 | |
| 330 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 331 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 332 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 333 | * <ul> |
| 334 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 335 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 336 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 337 | * </ul> |
| 338 | * |
| 339 | * @hide |
| 340 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 341 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 342 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 343 | public static final String ACTION_PROVISION_FINALIZATION |
| 344 | = "android.app.action.PROVISION_FINALIZATION"; |
| 345 | |
| 346 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 347 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 348 | * |
| 349 | * @hide |
| 350 | */ |
| 351 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 352 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 353 | |
| 354 | /** |
| 355 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 356 | * |
| 357 | * @hide |
| 358 | */ |
| 359 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 360 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 361 | |
| 362 | /** |
| 363 | * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}. |
| 364 | * |
| 365 | * @hide |
| 366 | */ |
| 367 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 368 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 369 | |
| 370 | /** |
| 371 | * Extra for shared bugreport's SHA-256 hash. |
| 372 | * |
| 373 | * @hide |
| 374 | */ |
| 375 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 376 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 377 | |
| 378 | /** |
| 379 | * Extra for remote bugreport notification shown type. |
| 380 | * |
| 381 | * @hide |
| 382 | */ |
| 383 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 384 | "android.app.extra.bugreport_notification_type"; |
| 385 | |
| 386 | /** |
| 387 | * Notification type for a started remote bugreport flow. |
| 388 | * |
| 389 | * @hide |
| 390 | */ |
| 391 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 392 | |
| 393 | /** |
| 394 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 395 | * being taken. |
| 396 | * |
| 397 | * @hide |
| 398 | */ |
| 399 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 400 | |
| 401 | /** |
| 402 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 403 | * |
| 404 | * @hide |
| 405 | */ |
| 406 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 407 | |
| 408 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 409 | * 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] | 410 | * allows a mobile device management application or NFC programmer application which starts |
| 411 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 412 | * <p> |
| 413 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 414 | * sends the intent to pass data to itself on the newly created profile. |
| 415 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 416 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 417 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 418 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 419 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 420 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 421 | * management application after provisioning. |
| 422 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 423 | * <p> |
| 424 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 425 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 426 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 427 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 428 | */ |
| 429 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 430 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 431 | |
| 432 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 433 | * A String extra holding the package name of the mobile device management application that |
| 434 | * will be set as the profile owner or device owner. |
| 435 | * |
| 436 | * <p>If an application starts provisioning directly via an intent with action |
| 437 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 438 | * application that started provisioning. The package will be set as profile owner in that case. |
| 439 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 440 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 441 | * 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] | 442 | * |
| 443 | * <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] | 444 | * 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] | 445 | |
| 446 | * @see DeviceAdminReceiver |
| 447 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 448 | * supported, but only if there is only one device admin receiver in the package that requires |
| 449 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 450 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 451 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 452 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 453 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 454 | |
| 455 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 456 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 457 | * application that will be set as the profile owner or device owner and active admin. |
| 458 | * |
| 459 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 460 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 461 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 462 | * 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] | 463 | * |
| 464 | * <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] | 465 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 466 | * message containing an NFC record with MIME type |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 467 | * {@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] | 468 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 469 | * |
| 470 | * @see DeviceAdminReceiver |
| 471 | */ |
| 472 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 473 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 474 | |
| 475 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 476 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 477 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 478 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 479 | * |
| 480 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 481 | */ |
| 482 | |
| 483 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 484 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 485 | |
| 486 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 487 | * A String extra that, holds the email address of the account which a managed profile is |
| 488 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 489 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 490 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 491 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 492 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 493 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 494 | * contains this extra, it is forwarded in the |
| 495 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 496 | * device management application that was set as the profile owner during provisioning. |
| 497 | * 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] | 498 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 499 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 500 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 501 | |
| 502 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 503 | * A integer extra indicating the predominant color to show during the provisioning. |
| 504 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 505 | * |
| 506 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 507 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 508 | */ |
| 509 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 510 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 511 | |
| 512 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 513 | * 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] | 514 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 515 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 516 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 517 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 518 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 519 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 520 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 521 | |
| 522 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 523 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 524 | * will be set to. |
| 525 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 526 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 527 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 528 | */ |
| 529 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 530 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 531 | |
| 532 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 533 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 534 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 535 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 536 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 537 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 538 | */ |
| 539 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 540 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 541 | |
| 542 | /** |
| 543 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 544 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 545 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 546 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 547 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 548 | */ |
| 549 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 550 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 551 | |
| 552 | /** |
| 553 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 554 | * owner provisioning for downloading the mobile device management application. |
| 555 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 556 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 557 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 558 | */ |
| 559 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 560 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 561 | |
| 562 | /** |
| 563 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 564 | * is hidden or not. |
| 565 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 566 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 567 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 568 | */ |
| 569 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 570 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 571 | |
| 572 | /** |
| 573 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 574 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 575 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 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_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 581 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 582 | |
| 583 | /** |
| 584 | * A String extra holding the password of the wifi network in |
| 585 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 586 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 587 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 588 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 589 | */ |
| 590 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 591 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * A String extra holding the proxy host for the wifi network in |
| 595 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 596 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 597 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 598 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 599 | */ |
| 600 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 601 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | |
| 603 | /** |
| 604 | * An int extra holding the proxy port for the wifi network in |
| 605 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 606 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 607 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 608 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 609 | */ |
| 610 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 611 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | |
| 613 | /** |
| 614 | * A String extra holding the proxy bypass for the wifi network in |
| 615 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 616 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 617 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 618 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 619 | */ |
| 620 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 621 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 625 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 626 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 627 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 628 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 629 | */ |
| 630 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 631 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 632 | |
| 633 | /** |
| 634 | * A String extra holding a url that specifies the download location of the device admin |
| 635 | * package. When not provided it is assumed that the device admin package is already installed. |
| 636 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 637 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 638 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 639 | */ |
| 640 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 641 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 642 | |
| 643 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 644 | * An int extra holding a minimum required version code for the device admin package. If the |
| 645 | * device admin is already installed on the device, it will only be re-downloaded from |
| 646 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 647 | * installed package is less than this version code. |
| 648 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 649 | * <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] | 650 | * provisioning via an NFC bump. |
| 651 | */ |
| 652 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 653 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 654 | |
| 655 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 656 | * A String extra holding a http cookie header which should be used in the http request to the |
| 657 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 658 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 659 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 660 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 661 | */ |
| 662 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 663 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 664 | |
| 665 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 666 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 667 | * the file at download location specified in |
| 668 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 669 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 670 | * <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] | 671 | * present. The provided checksum should match the checksum of the file at the download |
| 672 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 673 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 674 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 675 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 676 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 677 | * |
| 678 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 679 | * 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] | 680 | * 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] | 681 | * 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] | 682 | */ |
| 683 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 684 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 685 | |
| 686 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 687 | * 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] | 688 | * android package archive at the download location specified in {@link |
| 689 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 690 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 691 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 692 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 693 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 694 | * |
| 695 | * <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] | 696 | * 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] | 697 | * the download location. If the checksum does not match an error will be shown to the user and |
| 698 | * the user will be asked to factory reset the device. |
| 699 | * |
| 700 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 701 | * provisioning via an NFC bump. |
| 702 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 703 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 704 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 705 | |
| 706 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 707 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 708 | * has completed successfully. |
| 709 | * |
| 710 | * <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] | 711 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 712 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 713 | * <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] | 714 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 715 | */ |
| 716 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 717 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 718 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 719 | |
| 720 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 721 | * 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] | 722 | * provisioning. |
| 723 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 724 | * <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] | 725 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 726 | */ |
| 727 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 728 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 729 | |
| 730 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 731 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 732 | * provisioning. If this extra is not passed, a default image will be shown. |
| 733 | * <h5>The following URI schemes are accepted:</h5> |
| 734 | * <ul> |
| 735 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 736 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 737 | * </ul> |
| 738 | * |
| 739 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 740 | * pixed density for the device. |
| 741 | * |
| 742 | * <p> If a content: URI is passed, the intent should have the flag |
| 743 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 744 | * {@link android.content.ClipData} of the intent too. |
| 745 | * |
| 746 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 747 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 748 | */ |
| 749 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 750 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 751 | |
| 752 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 753 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 754 | * during setup-wizard. |
| 755 | * |
| 756 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 757 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 758 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 759 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 760 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 761 | * |
| 762 | * @hide |
| 763 | */ |
| 764 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 765 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 766 | |
| 767 | /** |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 768 | * This MIME type is used for starting the Device Owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 769 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 770 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 771 | * A device owner has full control over the device. The device owner can not be modified by the |
| 772 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 773 | * reset. |
| 774 | * |
| 775 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 776 | * employee or client. |
| 777 | * |
| 778 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 779 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 780 | * <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] | 781 | * contains the following properties: |
| 782 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 783 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 784 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 785 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 786 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 787 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 788 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 789 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 790 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 791 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 792 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 793 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 794 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 795 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 796 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 797 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 798 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 799 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 800 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 801 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 802 | * 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] | 803 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 804 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 805 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 806 | */ |
| 807 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 808 | = "application/com.android.managedprovisioning"; |
| 809 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 810 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 811 | * Activity action: ask the user to add a new device administrator to the system. |
| 812 | * The desired policy is the ComponentName of the policy in the |
| 813 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 814 | * bring the user through adding the device administrator to the system (or |
| 815 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 816 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 817 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 818 | * field to provide the user with additional explanation (in addition |
| 819 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 820 | * |
| 821 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 822 | * user intervention). However, if your administrator has been updated and is requesting |
| 823 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 824 | * 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] | 825 | */ |
| 826 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 827 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 828 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 829 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 830 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 831 | * @hide |
| 832 | * 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] | 833 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 834 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 835 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 836 | * 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] | 837 | * to remotely control restrictions on the user. |
| 838 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 839 | * <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] | 840 | * result of whether or not the user approved the action. If approved, the result will |
| 841 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 842 | * as a profile owner. |
| 843 | * |
| 844 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 845 | * field to provide the user with additional explanation (in addition |
| 846 | * to your component's description) about what is being added. |
| 847 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 848 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 849 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 850 | */ |
| 851 | @SystemApi |
| 852 | public static final String ACTION_SET_PROFILE_OWNER |
| 853 | = "android.app.action.SET_PROFILE_OWNER"; |
| 854 | |
| 855 | /** |
| 856 | * @hide |
| 857 | * Name of the profile owner admin that controls the user. |
| 858 | */ |
| 859 | @SystemApi |
| 860 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 861 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 862 | |
| 863 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 864 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 865 | * 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] | 866 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 867 | * @hide |
| 868 | */ |
| 869 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 870 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 871 | |
| 872 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 873 | * Broadcast action: sent when the device owner is set or changed. |
| 874 | * |
| 875 | * This broadcast is sent only to the primary user. |
| 876 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 877 | */ |
| 878 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 879 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 880 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 881 | |
| 882 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 883 | * The ComponentName of the administrator component. |
| 884 | * |
| 885 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 886 | */ |
| 887 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 888 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 889 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 890 | * An optional CharSequence providing additional explanation for why the |
| 891 | * admin is being added. |
| 892 | * |
| 893 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 894 | */ |
| 895 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 896 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 897 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 898 | * Activity action: have the user enter a new password. This activity should |
| 899 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 900 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 901 | * enter a new password that meets the current requirements. You can use |
| 902 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 903 | * have the user select a new password in order to meet the current |
| 904 | * constraints. Upon being resumed from this activity, you can check the new |
| 905 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 906 | * |
| 907 | * If the intent is launched from within a managed profile with a profile |
| 908 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 909 | * this will trigger entering a new password for the parent of the profile. |
| 910 | * For all other cases it will trigger entering a new password for the user |
| 911 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 912 | * |
| 913 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 914 | */ |
| 915 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 916 | public static final String ACTION_SET_NEW_PASSWORD |
| 917 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 918 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 919 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 920 | * Activity action: have the user enter a new password for the parent profile. |
| 921 | * If the intent is launched from within a managed profile, this will trigger |
| 922 | * entering a new password for the parent of the profile. In all other cases |
| 923 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 924 | */ |
| 925 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 926 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 927 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 928 | |
| 929 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 930 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 931 | * the parent profile to access intents sent from the managed profile. |
| 932 | * That is, when an app in the managed profile calls |
| 933 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 934 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 935 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 936 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 937 | |
| 938 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 939 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 940 | * the managed profile to access intents sent from the parent profile. |
| 941 | * That is, when an app in the parent profile calls |
| 942 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 943 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 944 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 945 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 946 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 947 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 948 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 949 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 950 | */ |
| 951 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 952 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 953 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 954 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 955 | /** |
| 956 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 957 | * Already granted or denied permissions are not affected by this. |
| 958 | */ |
| 959 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 960 | |
| 961 | /** |
| 962 | * Permission policy to always grant new permission requests for runtime permissions. |
| 963 | * Already granted or denied permissions are not affected by this. |
| 964 | */ |
| 965 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 966 | |
| 967 | /** |
| 968 | * Permission policy to always deny new permission requests for runtime permissions. |
| 969 | * Already granted or denied permissions are not affected by this. |
| 970 | */ |
| 971 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 972 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 973 | /** |
| 974 | * Runtime permission state: The user can manage the permission |
| 975 | * through the UI. |
| 976 | */ |
| 977 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 978 | |
| 979 | /** |
| 980 | * Runtime permission state: The permission is granted to the app |
| 981 | * and the user cannot manage the permission through the UI. |
| 982 | */ |
| 983 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 984 | |
| 985 | /** |
| 986 | * Runtime permission state: The permission is denied to the app |
| 987 | * and the user cannot manage the permission through the UI. |
| 988 | */ |
| 989 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 990 | |
| 991 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 992 | * No management for current user in-effect. This is the default. |
| 993 | * @hide |
| 994 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 995 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 996 | public static final int STATE_USER_UNMANAGED = 0; |
| 997 | |
| 998 | /** |
| 999 | * Management partially setup, user setup needs to be completed. |
| 1000 | * @hide |
| 1001 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1002 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1003 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1004 | |
| 1005 | /** |
| 1006 | * Management partially setup, user setup completed. |
| 1007 | * @hide |
| 1008 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1009 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1010 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1011 | |
| 1012 | /** |
| 1013 | * Management setup and active on current user. |
| 1014 | * @hide |
| 1015 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1016 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1017 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1018 | |
| 1019 | /** |
| 1020 | * Management partially setup on a managed profile. |
| 1021 | * @hide |
| 1022 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1023 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1024 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1025 | |
| 1026 | /** |
| 1027 | * @hide |
| 1028 | */ |
| 1029 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1030 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1031 | @Retention(RetentionPolicy.SOURCE) |
| 1032 | public @interface UserProvisioningState {} |
| 1033 | |
| 1034 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1035 | * Return true if the given administrator component is currently |
| 1036 | * active (enabled) in the system. |
| 1037 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1038 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1039 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * @see #isAdminActive(ComponentName) |
| 1044 | * @hide |
| 1045 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1046 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1047 | if (mService != null) { |
| 1048 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1049 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1050 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1051 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | return false; |
| 1055 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1056 | /** |
| 1057 | * Return true if the given administrator component is currently being removed |
| 1058 | * for the user. |
| 1059 | * @hide |
| 1060 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1061 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1062 | if (mService != null) { |
| 1063 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1064 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1065 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1066 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | return false; |
| 1070 | } |
| 1071 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1072 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1073 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1074 | * Return a list of all currently active device administrators' component |
| 1075 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1076 | * returned. |
| 1077 | */ |
| 1078 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1079 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * @see #getActiveAdmins() |
| 1084 | * @hide |
| 1085 | */ |
| 1086 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1087 | if (mService != null) { |
| 1088 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1089 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1090 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1091 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | return null; |
| 1095 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1096 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1097 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1098 | * Used by package administration code to determine if a package can be stopped |
| 1099 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1100 | * @hide |
| 1101 | */ |
| 1102 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1103 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * Used by package administration code to determine if a package can be stopped |
| 1108 | * or uninstalled. |
| 1109 | * @hide |
| 1110 | */ |
| 1111 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1112 | if (mService != null) { |
| 1113 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1114 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1115 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1116 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | return false; |
| 1120 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1121 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1122 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1123 | * Remove a current administration component. This can only be called |
| 1124 | * by the application that owns the administration component; if you |
| 1125 | * try to remove someone else's component, a security exception will be |
| 1126 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1127 | * |
| 1128 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1129 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1130 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1131 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1132 | if (mService != null) { |
| 1133 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1134 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1135 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1136 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1140 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1141 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1142 | * 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] | 1143 | * 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] | 1144 | * but requires additional policies after an upgrade. |
| 1145 | * |
| 1146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 1147 | * an active administrator, or an exception will be thrown. |
| 1148 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 1149 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1150 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1151 | if (mService != null) { |
| 1152 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1153 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1154 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1155 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
| 1161 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1162 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1163 | * |
| 1164 | * @hide |
| 1165 | */ |
| 1166 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1167 | if (mService != null) { |
| 1168 | try { |
| 1169 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1170 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1171 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | return false; |
| 1175 | } |
| 1176 | |
| 1177 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1178 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1179 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1180 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1181 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1182 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1183 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1184 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1185 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1186 | * recognition technology. This implies technologies that can recognize the identity of |
| 1187 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1188 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1189 | */ |
| 1190 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1191 | |
| 1192 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1193 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1194 | * 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] | 1195 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1196 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1197 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1198 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1199 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1200 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1201 | * password containing at least numeric characters. Note that quality |
| 1202 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1203 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1204 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1205 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1206 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1207 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1208 | * password containing at least numeric characters with no repeating (4444) |
| 1209 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1210 | * constants are ordered so that higher values are more restrictive. |
| 1211 | */ |
| 1212 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1213 | |
| 1214 | /** |
| 1215 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1216 | * password containing at least alphabetic (or other symbol) characters. |
| 1217 | * Note that quality constants are ordered so that higher values are more |
| 1218 | * restrictive. |
| 1219 | */ |
| 1220 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1221 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1222 | /** |
| 1223 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1224 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1225 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1226 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1227 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1228 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1229 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1230 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1231 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1232 | * password containing at least a letter, a numerical digit and a special |
| 1233 | * symbol, by default. With this password quality, passwords can be |
| 1234 | * restricted to contain various sets of characters, like at least an |
| 1235 | * uppercase letter, etc. These are specified using various methods, |
| 1236 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1237 | * that quality constants are ordered so that higher values are more |
| 1238 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1239 | */ |
| 1240 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1241 | |
| 1242 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1243 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1244 | * modify password. In case this password quality is set, the password is |
| 1245 | * managed by a profile owner. The profile owner can set any password, |
| 1246 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1247 | * that quality constants are ordered so that higher values are more |
| 1248 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1249 | * the highest. |
| 1250 | * @hide |
| 1251 | */ |
| 1252 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1253 | |
| 1254 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1255 | * Called by an application that is administering the device to set the |
| 1256 | * password restrictions it is imposing. After setting this, the user |
| 1257 | * will not be able to enter a new password that is not at least as |
| 1258 | * restrictive as what has been set. Note that the current password |
| 1259 | * will remain until the user has set a new one, so the change does not |
| 1260 | * take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1261 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1262 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1263 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1264 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 1265 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1266 | * the user's preference, and any other considerations) is the one that |
| 1267 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1268 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1269 | * <p>The calling device admin must have requested |
| 1270 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1271 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1272 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1273 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1274 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1275 | * restrictions on the parent profile. |
| 1276 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1277 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1278 | * @param quality The new desired quality. One of |
| 1279 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1280 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1281 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1282 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1283 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1284 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1285 | if (mService != null) { |
| 1286 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1287 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1288 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1289 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1293 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1294 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1295 | * Retrieve the current minimum password quality for a particular admin or all admins that set |
| 1296 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1297 | * a separate challenge are not taken into account. |
| 1298 | * |
| 1299 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1300 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1301 | * restrictions on the parent profile. |
| 1302 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1303 | * @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] | 1304 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1305 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1306 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1307 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1311 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1312 | if (mService != null) { |
| 1313 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1314 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1315 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1316 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1317 | } |
| 1318 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1319 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1320 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1321 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1322 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1323 | * Called by an application that is administering the device to set the |
| 1324 | * minimum allowed password length. After setting this, the user |
| 1325 | * will not be able to enter a new password that is not at least as |
| 1326 | * restrictive as what has been set. Note that the current password |
| 1327 | * will remain until the user has set a new one, so the change does not |
| 1328 | * take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1329 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1330 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1331 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1332 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1333 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1334 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1335 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1336 | * <p>The calling device admin must have requested |
| 1337 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1338 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1339 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1340 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1341 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1342 | * restrictions on the parent profile. |
| 1343 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1344 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1345 | * @param length The new desired minimum password length. A value of 0 |
| 1346 | * means there is no restriction. |
| 1347 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1348 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1349 | if (mService != null) { |
| 1350 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1351 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1352 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1353 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1357 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1358 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1359 | * Retrieve the current minimum password length for a particular admin or all admins that set |
| 1360 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1361 | * a separate challenge are not taken into account. |
| 1362 | * |
| 1363 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1364 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1365 | * restrictions on the parent profile. |
| 1366 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1367 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1368 | * @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] | 1369 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1370 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1371 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1372 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1376 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1377 | if (mService != null) { |
| 1378 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1379 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1380 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1381 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | return 0; |
| 1385 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1386 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1387 | /** |
| 1388 | * Called by an application that is administering the device to set the |
| 1389 | * minimum number of upper case letters required in the password. After |
| 1390 | * setting this, the user will not be able to enter a new password that is |
| 1391 | * not at least as restrictive as what has been set. Note that the current |
| 1392 | * password will remain until the user has set a new one, so the change does |
| 1393 | * not take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1394 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1395 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1396 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1397 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1398 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1399 | * <p> |
| 1400 | * The calling device admin must have requested |
| 1401 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1402 | * this method; if it has not, a security exception will be thrown. |
| 1403 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1404 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1405 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1406 | * restrictions on the parent profile. |
| 1407 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1408 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1409 | * with. |
| 1410 | * @param length The new desired minimum number of upper case letters |
| 1411 | * required in the password. A value of 0 means there is no |
| 1412 | * restriction. |
| 1413 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1414 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1415 | if (mService != null) { |
| 1416 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1417 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1418 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1419 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1420 | } |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1425 | * Retrieve the current number of upper case letters required in the password |
| 1426 | * for a particular admin or all admins that set retrictions on this user and |
| 1427 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1428 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1429 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1430 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1431 | * and only applies when the password quality is |
| 1432 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1433 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1434 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1435 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1436 | * restrictions on the parent profile. |
| 1437 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1438 | * @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] | 1439 | * aggregate all admins. |
| 1440 | * @return The minimum number of upper case letters required in the |
| 1441 | * password. |
| 1442 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1443 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1444 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1448 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1449 | if (mService != null) { |
| 1450 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1451 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1452 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1453 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * Called by an application that is administering the device to set the |
| 1461 | * minimum number of lower case letters required in the password. After |
| 1462 | * setting this, the user will not be able to enter a new password that is |
| 1463 | * not at least as restrictive as what has been set. Note that the current |
| 1464 | * password will remain until the user has set a new one, so the change does |
| 1465 | * not take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1466 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1467 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1468 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1469 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1470 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1471 | * <p> |
| 1472 | * The calling device admin must have requested |
| 1473 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1474 | * this method; if it has not, a security exception will be thrown. |
| 1475 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1476 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1477 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1478 | * restrictions on the parent profile. |
| 1479 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1480 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1481 | * with. |
| 1482 | * @param length The new desired minimum number of lower case letters |
| 1483 | * required in the password. A value of 0 means there is no |
| 1484 | * restriction. |
| 1485 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1486 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1487 | if (mService != null) { |
| 1488 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1489 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1490 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1491 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1497 | * Retrieve the current number of lower case letters required in the password |
| 1498 | * for a particular admin or all admins that set retrictions on this user |
| 1499 | * and its participating profiles. Restrictions on profiles that have |
| 1500 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1501 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1502 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1503 | * and only applies when the password quality is |
| 1504 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1505 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1506 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1507 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1508 | * restrictions on the parent profile. |
| 1509 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1510 | * @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] | 1511 | * aggregate all admins. |
| 1512 | * @return The minimum number of lower case letters required in the |
| 1513 | * password. |
| 1514 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1515 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1516 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1520 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1521 | if (mService != null) { |
| 1522 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1523 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1524 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1525 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * Called by an application that is administering the device to set the |
| 1533 | * minimum number of letters required in the password. After setting this, |
| 1534 | * the user will not be able to enter a new password that is not at least as |
| 1535 | * restrictive as what has been set. Note that the current password will |
| 1536 | * remain until the user has set a new one, so the change does not take |
| 1537 | * place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1538 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1539 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1540 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1541 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1542 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1543 | * <p> |
| 1544 | * The calling device admin must have requested |
| 1545 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1546 | * this method; if it has not, a security exception will be thrown. |
| 1547 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1548 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1549 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1550 | * restrictions on the parent profile. |
| 1551 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1552 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1553 | * with. |
| 1554 | * @param length The new desired minimum number of letters required in the |
| 1555 | * password. A value of 0 means there is no restriction. |
| 1556 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1557 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1558 | if (mService != null) { |
| 1559 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1560 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1561 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1562 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1568 | * Retrieve the current number of letters required in the password |
| 1569 | * for a particular admin or all admins that set retrictions on this user |
| 1570 | * and its participating profiles. Restrictions on profiles that have |
| 1571 | * a separate challenge are not taken into account. |
| 1572 | * This is the same value as set by |
| 1573 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1574 | * and only applies when the password quality is |
| 1575 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1576 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1577 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1578 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1579 | * restrictions on the parent profile. |
| 1580 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1581 | * @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] | 1582 | * aggregate all admins. |
| 1583 | * @return The minimum number of letters required in the password. |
| 1584 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1585 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1586 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1590 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1591 | if (mService != null) { |
| 1592 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1593 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1594 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1595 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1596 | } |
| 1597 | } |
| 1598 | return 0; |
| 1599 | } |
| 1600 | |
| 1601 | /** |
| 1602 | * Called by an application that is administering the device to set the |
| 1603 | * minimum number of numerical digits required in the password. After |
| 1604 | * setting this, the user will not be able to enter a new password that is |
| 1605 | * not at least as restrictive as what has been set. Note that the current |
| 1606 | * password will remain until the user has set a new one, so the change does |
| 1607 | * not take place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1608 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1609 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1610 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1611 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1612 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1613 | * <p> |
| 1614 | * The calling device admin must have requested |
| 1615 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1616 | * this method; if it has not, a security exception will be thrown. |
| 1617 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1618 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1619 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1620 | * restrictions on the parent profile. |
| 1621 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1622 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1623 | * with. |
| 1624 | * @param length The new desired minimum number of numerical digits required |
| 1625 | * in the password. A value of 0 means there is no restriction. |
| 1626 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1627 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1628 | if (mService != null) { |
| 1629 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1630 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1631 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1632 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1633 | } |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | /** |
| 1638 | * Retrieve the current number of numerical digits required in the password |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1639 | * for a particular admin or all admins that set retrictions on this user |
| 1640 | * and its participating profiles. Restrictions on profiles that have |
| 1641 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1642 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1643 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1644 | * and only applies when the password quality is |
| 1645 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1646 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1647 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1648 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1649 | * restrictions on the parent profile. |
| 1650 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1651 | * @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] | 1652 | * aggregate all admins. |
| 1653 | * @return The minimum number of numerical digits required in the password. |
| 1654 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1655 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1656 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1660 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1661 | if (mService != null) { |
| 1662 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1663 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1664 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1665 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * Called by an application that is administering the device to set the |
| 1673 | * minimum number of symbols required in the password. After setting this, |
| 1674 | * the user will not be able to enter a new password that is not at least as |
| 1675 | * restrictive as what has been set. Note that the current password will |
| 1676 | * remain until the user has set a new one, so the change does not take |
| 1677 | * place immediately. To prompt the user for a new password, use |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1678 | * {@link #ACTION_SET_NEW_PASSWORD} or |
| 1679 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1680 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1681 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1682 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1683 | * <p> |
| 1684 | * The calling device admin must have requested |
| 1685 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1686 | * this method; if it has not, a security exception will be thrown. |
| 1687 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1688 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1689 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1690 | * restrictions on the parent profile. |
| 1691 | * |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1692 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1693 | * with. |
| 1694 | * @param length The new desired minimum number of symbols required in the |
| 1695 | * password. A value of 0 means there is no restriction. |
| 1696 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1697 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1698 | if (mService != null) { |
| 1699 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1700 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1701 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1702 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1703 | } |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1708 | * Retrieve the current number of symbols required in the password |
| 1709 | * for a particular admin or all admins that set retrictions on this user |
| 1710 | * and its participating profiles. Restrictions on profiles that have |
| 1711 | * a separate challenge are not taken into account. This is the same value as |
| 1712 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1713 | * and only applies when the password quality is |
| 1714 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1715 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1716 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1717 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1718 | * restrictions on the parent profile. |
| 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 |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1721 | * aggregate all admins. |
| 1722 | * @return The minimum number of symbols required in the password. |
| 1723 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1724 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1725 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1729 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1730 | if (mService != null) { |
| 1731 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1732 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1733 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1734 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1740 | /** |
| 1741 | * Called by an application that is administering the device to set the |
| 1742 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1743 | * required in the password. After setting this, the user will not be able |
| 1744 | * to enter a new password that is not at least as restrictive as what has |
| 1745 | * been set. Note that the current password will remain until the user has |
| 1746 | * set a new one, so the change does not take place immediately. To prompt |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1747 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1748 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1749 | * setting this value. This constraint is only imposed if the administrator |
| 1750 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1751 | * {@link #setPasswordQuality}. The default value is 0. |
| 1752 | * <p> |
| 1753 | * The calling device admin must have requested |
| 1754 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1755 | * this method; if it has not, a security exception will be thrown. |
| 1756 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1757 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1758 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1759 | * restrictions on the parent profile. |
| 1760 | * |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1761 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1762 | * with. |
| 1763 | * @param length The new desired minimum number of letters required in the |
| 1764 | * password. A value of 0 means there is no restriction. |
| 1765 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1766 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1767 | if (mService != null) { |
| 1768 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1769 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1770 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1771 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1777 | * Retrieve the current number of non-letter characters required in the password |
| 1778 | * for a particular admin or all admins that set retrictions on this user |
| 1779 | * and its participating profiles. Restrictions on profiles that have |
| 1780 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1781 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1782 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1783 | * and only applies when the password quality is |
| 1784 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1785 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1786 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1787 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1788 | * restrictions on the parent profile. |
| 1789 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1790 | * @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] | 1791 | * aggregate all admins. |
| 1792 | * @return The minimum number of letters required in the password. |
| 1793 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1794 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1795 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1799 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1800 | if (mService != null) { |
| 1801 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1802 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1803 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1804 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1810 | /** |
| 1811 | * Called by an application that is administering the device to set the length |
| 1812 | * of the password history. After setting this, the user will not be able to |
| 1813 | * enter a new password that is the same as any password in the history. Note |
| 1814 | * that the current password will remain until the user has set a new one, so |
| 1815 | * the change does not take place immediately. To prompt the user for a new |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1816 | * password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1817 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1818 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1819 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1820 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1821 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1822 | * |
| 1823 | * <p> |
| 1824 | * The calling device admin must have requested |
| 1825 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1826 | * method; if it has not, a security exception will be thrown. |
| 1827 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1828 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1829 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1830 | * restrictions on the parent profile. |
| 1831 | * |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1832 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1833 | * with. |
| 1834 | * @param length The new desired length of password history. A value of 0 |
| 1835 | * means there is no restriction. |
| 1836 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1837 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1838 | if (mService != null) { |
| 1839 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1840 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1841 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1842 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1848 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1849 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1850 | * the device password (for all admins). |
| 1851 | * |
| 1852 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1853 | * For example, to have the password expire 5 days from now, timeout would be |
| 1854 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1855 | * |
| 1856 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1857 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1858 | * <p>The calling device admin must have requested |
| 1859 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1860 | * method; if it has not, a security exception will be thrown. |
| 1861 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1862 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1863 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1864 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1865 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1866 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 1867 | * restrictions on the parent profile. |
| 1868 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1869 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1870 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1871 | * means there is no restriction (unlimited). |
| 1872 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1873 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1874 | if (mService != null) { |
| 1875 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1876 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1877 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1878 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1879 | } |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1884 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1885 | * recurring expiration timeout provided in the call to |
| 1886 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1887 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 1888 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 1889 | * |
| 1890 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1891 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1892 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1893 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1894 | * @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] | 1895 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1896 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1897 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1898 | if (mService != null) { |
| 1899 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1900 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1901 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1902 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1903 | } |
| 1904 | } |
| 1905 | return 0; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1909 | * Get the current password expiration time for a particular admin or all admins that set |
| 1910 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1911 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 1912 | * of all expiration times is returned - which will be the minimum of all of them. |
| 1913 | * |
| 1914 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1915 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1916 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1917 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1918 | * @param admin The name of the admin component to check, or {@code null} to aggregate all admins. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1919 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1920 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1921 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1922 | if (mService != null) { |
| 1923 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1924 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1925 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1926 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | return 0; |
| 1930 | } |
| 1931 | |
| 1932 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1933 | * Retrieve the current password history length for a particular admin or all admins that |
| 1934 | * set retrictions on this user and its participating profiles. Restrictions on profiles that |
| 1935 | * have a separate challenge are not taken into account. |
| 1936 | * |
| 1937 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1938 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1939 | * restrictions on the parent profile. |
| 1940 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1941 | * @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] | 1942 | * all admins. |
| 1943 | * @return The length of the password history |
| 1944 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1945 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1946 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1950 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1951 | if (mService != null) { |
| 1952 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1953 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1954 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1955 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1956 | } |
| 1957 | } |
| 1958 | return 0; |
| 1959 | } |
| 1960 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1961 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1962 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1963 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1964 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1965 | * @return Returns the maximum length that the user can enter. |
| 1966 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1967 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1968 | // Kind-of arbitrary. |
| 1969 | return 16; |
| 1970 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1971 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1972 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1973 | * Determine whether the current password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1974 | * to meet the policy requirements (e.g. quality, minimum length) that have been |
| 1975 | * requested by the admins of this user and its participating profiles. |
| 1976 | * Restrictions on profiles that have a separate challenge are not taken into account. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1977 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1978 | * <p>The calling device admin must have requested |
| 1979 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1980 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1981 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1982 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1983 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to determine |
| 1984 | * if the password set on the parent profile is sufficient. |
| 1985 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1986 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1987 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1988 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1989 | if (mService != null) { |
| 1990 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1991 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1992 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1993 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1994 | } |
| 1995 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1996 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1997 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1998 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1999 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2000 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2001 | * to meet the policy requirements (e.g. quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2002 | * requested by the admins of the parent user and its profiles. |
| 2003 | * |
| 2004 | * @param userHandle the userId of the profile to check the password for. |
| 2005 | * @return Returns true if the password would meet the current requirements, else false. |
| 2006 | * @hide |
| 2007 | */ |
| 2008 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2009 | if (mService != null) { |
| 2010 | try { |
| 2011 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2012 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2013 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | return false; |
| 2017 | } |
| 2018 | |
| 2019 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2020 | * Retrieve the number of times the user has failed at entering a |
| 2021 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2022 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2023 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2024 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2025 | * the number of failed password attemts for the parent user. |
| 2026 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2027 | * <p>The calling device admin must have requested |
| 2028 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 2029 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2030 | */ |
| 2031 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2032 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2033 | } |
| 2034 | |
| 2035 | /** |
| 2036 | * Retrieve the number of times the given user has failed at entering a |
| 2037 | * password since that last successful password entry. |
| 2038 | * |
| 2039 | * <p>The calling device admin must have requested |
| 2040 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2041 | * not and it is not the system uid, a security exception will be thrown. |
| 2042 | * |
| 2043 | * @hide |
| 2044 | */ |
| 2045 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2046 | if (mService != null) { |
| 2047 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2048 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2049 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2050 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | return -1; |
| 2054 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2055 | |
| 2056 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2057 | * 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] | 2058 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2059 | * @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] | 2060 | * @hide |
| 2061 | */ |
| 2062 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2063 | if (mService != null) { |
| 2064 | try { |
| 2065 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2066 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2067 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | return false; |
| 2071 | } |
| 2072 | |
| 2073 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2074 | * Setting this to a value greater than zero enables a built-in policy |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2075 | * that will perform a device or profile wipe after too many incorrect |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2076 | * device-unlock passwords have been entered. This built-in policy combines |
| 2077 | * watching for failed passwords and wiping the device, and requires |
| 2078 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2079 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2080 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2081 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 2082 | * application only, erasing or revoking credentials, or reporting the |
| 2083 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2084 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 2085 | * instead. Do not use this API, because if the maximum count is reached, |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2086 | * the device or profile will be wiped immediately, and your callback will not be invoked. |
| 2087 | * |
| 2088 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2089 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 2090 | * a value on the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2091 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2092 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2093 | * @param num The number of failed password attempts at which point the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2094 | * device or profile will be wiped. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2095 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2096 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2097 | if (mService != null) { |
| 2098 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2099 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2100 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2101 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2102 | } |
| 2103 | } |
| 2104 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2105 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2106 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2107 | * Retrieve the current maximum number of login attempts that are allowed before the device |
| 2108 | * or profile is wiped, for a particular admin or all admins that set retrictions on this user |
| 2109 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2110 | * not taken into account. |
| 2111 | * |
| 2112 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2113 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2114 | * the value for the parent profile. |
| 2115 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2116 | * @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] | 2117 | * all admins. |
| 2118 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2119 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2120 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2124 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2125 | if (mService != null) { |
| 2126 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2127 | return mService.getMaximumFailedPasswordsForWipe( |
| 2128 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2129 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2130 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2131 | } |
| 2132 | } |
| 2133 | return 0; |
| 2134 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2135 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2136 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2137 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2138 | * for the given user. So for primary user, it might return the primary or |
| 2139 | * a managed profile. For a secondary user, it would be the same as the |
| 2140 | * user passed in. |
| 2141 | * @hide Used only by Keyguard |
| 2142 | */ |
| 2143 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2144 | if (mService != null) { |
| 2145 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2146 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2147 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2148 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2149 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2150 | } |
| 2151 | } |
| 2152 | return UserHandle.USER_NULL; |
| 2153 | } |
| 2154 | |
| 2155 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2156 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2157 | * the password again until the user has entered it. |
| 2158 | */ |
| 2159 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2160 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2161 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2162 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2163 | * If the flag is set, the device can be booted without asking for user password. |
| 2164 | * The absence of this flag does not change the current boot requirements. This flag |
| 2165 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2166 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2167 | * device to factory defaults. |
| 2168 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2169 | 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] | 2170 | |
| 2171 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2172 | * Force a new device unlock password (the password needed to access the |
| 2173 | * entire device, not for individual accounts) on the user. This takes |
| 2174 | * effect immediately. |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2175 | * |
| 2176 | * <p>Calling this from a managed profile that shares the password with the owner profile |
| 2177 | * will throw a security exception. |
| 2178 | * |
| 2179 | * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
| 2180 | * device admins that are not device owner and not profile owner. |
| 2181 | * The password can now only be changed if there is currently no password set. Device owner |
| 2182 | * and profile owner can still do this.</em> |
| 2183 | * |
| 2184 | * <p>The given password must be sufficient for the |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2185 | * current password quality and length constraints as returned by |
| 2186 | * {@link #getPasswordQuality(ComponentName)} and |
| 2187 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 2188 | * these constraints, then it will be rejected and false returned. Note |
| 2189 | * that the password may be a stronger quality (containing alphanumeric |
| 2190 | * characters when the requested quality is only numeric), in which case |
| 2191 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2192 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2193 | * <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] | 2194 | * pattern or password if the current password constraints allow it. <em>Note: This will not |
| 2195 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 2196 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 2197 | * empty, except by device owner or profile owner.</em> |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2198 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2199 | * <p>The calling device admin must have requested |
| 2200 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 2201 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2202 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2203 | * @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] | 2204 | * @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] | 2205 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2206 | * @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] | 2207 | * 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] | 2208 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2209 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2210 | if (mParentInstance) { |
| 2211 | throw new SecurityException("Reset password does not work across profiles."); |
| 2212 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2213 | if (mService != null) { |
| 2214 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2215 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2216 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2217 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | return false; |
| 2221 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2222 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2223 | /** |
| 2224 | * Called by an application that is administering the device to set the |
| 2225 | * maximum time for user activity until the device will lock. This limits |
| 2226 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2227 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2228 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 2229 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2230 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2231 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2232 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2233 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to set |
| 2234 | * restrictions on the parent profile. |
| 2235 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2236 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2237 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 2238 | * A value of 0 means there is no restriction. |
| 2239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2240 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2241 | if (mService != null) { |
| 2242 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2243 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2244 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2245 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2246 | } |
| 2247 | } |
| 2248 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2249 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2250 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2251 | * Retrieve the current maximum time to unlock for a particular admin or all admins that set |
| 2252 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 2253 | * a separate challenge are not taken into account. |
| 2254 | * |
| 2255 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2256 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2257 | * restrictions on the parent profile. |
| 2258 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2259 | * @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] | 2260 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2261 | * @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] | 2262 | * 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] | 2263 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2264 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2265 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2269 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2270 | if (mService != null) { |
| 2271 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2272 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2273 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2274 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | return 0; |
| 2278 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2279 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2280 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2281 | * Make the device lock immediately, as if the lock screen timeout has |
| 2282 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2283 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2284 | * <p>The calling device admin must have requested |
| 2285 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 2286 | * this method; if it has not, a security exception will be thrown. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2287 | * |
| 2288 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2289 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to lock |
| 2290 | * the parent profile. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2291 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2292 | public void lockNow() { |
| 2293 | if (mService != null) { |
| 2294 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2295 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2296 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2297 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2301 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2302 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2303 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2304 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2305 | */ |
| 2306 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2307 | |
| 2308 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2309 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2310 | * data. |
| 2311 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2312 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2313 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2314 | */ |
| 2315 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2316 | |
| 2317 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 2318 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 2319 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2320 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2321 | * <p>The calling device admin must have requested |
| 2322 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 2323 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2324 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2325 | * @param flags Bit mask of additional options: currently supported flags |
| 2326 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 2327 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2328 | */ |
| 2329 | public void wipeData(int flags) { |
| 2330 | if (mService != null) { |
| 2331 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2332 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2333 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2334 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2338 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2339 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2340 | * Called by an application that is administering the device to set the |
| 2341 | * global proxy and exclusion list. |
| 2342 | * <p> |
| 2343 | * The calling device admin must have requested |
| 2344 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2345 | * this method; if it has not, a security exception will be thrown. |
| 2346 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2347 | * 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] | 2348 | * 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] | 2349 | * be returned. |
| 2350 | * The method can be called repeatedly by the device admin alrady setting the |
| 2351 | * proxy to update the proxy and exclusion list. |
| 2352 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2353 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2354 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2355 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2356 | * @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] | 2357 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2358 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2359 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2360 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2361 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2362 | List<String> exclusionList ) { |
| 2363 | if (proxySpec == null) { |
| 2364 | throw new NullPointerException(); |
| 2365 | } |
| 2366 | if (mService != null) { |
| 2367 | try { |
| 2368 | String hostSpec; |
| 2369 | String exclSpec; |
| 2370 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2371 | hostSpec = null; |
| 2372 | exclSpec = null; |
| 2373 | } else { |
| 2374 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2375 | throw new IllegalArgumentException(); |
| 2376 | } |
| 2377 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2378 | String hostName = sa.getHostName(); |
| 2379 | int port = sa.getPort(); |
| 2380 | StringBuilder hostBuilder = new StringBuilder(); |
| 2381 | hostSpec = hostBuilder.append(hostName) |
| 2382 | .append(":").append(Integer.toString(port)).toString(); |
| 2383 | if (exclusionList == null) { |
| 2384 | exclSpec = ""; |
| 2385 | } else { |
| 2386 | StringBuilder listBuilder = new StringBuilder(); |
| 2387 | boolean firstDomain = true; |
| 2388 | for (String exclDomain : exclusionList) { |
| 2389 | if (!firstDomain) { |
| 2390 | listBuilder = listBuilder.append(","); |
| 2391 | } else { |
| 2392 | firstDomain = false; |
| 2393 | } |
| 2394 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2395 | } |
| 2396 | exclSpec = listBuilder.toString(); |
| 2397 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2398 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2399 | != android.net.Proxy.PROXY_VALID) |
| 2400 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2401 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2402 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2403 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2404 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | return null; |
| 2408 | } |
| 2409 | |
| 2410 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2411 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 2412 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 2413 | * doing something unusual like general internal filtering this may be useful. On |
| 2414 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 2415 | * |
| 2416 | * <p>This method requires the caller to be the device owner. |
| 2417 | * |
| 2418 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 2419 | * @see ProxyInfo |
| 2420 | * |
| 2421 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2422 | * with. |
| 2423 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 2424 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 2425 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2426 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2427 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2428 | if (mService != null) { |
| 2429 | try { |
| 2430 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2431 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2432 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2438 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2439 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2440 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2441 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2442 | */ |
| 2443 | public ComponentName getGlobalProxyAdmin() { |
| 2444 | if (mService != null) { |
| 2445 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2446 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2447 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2448 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2449 | } |
| 2450 | } |
| 2451 | return null; |
| 2452 | } |
| 2453 | |
| 2454 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2455 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2456 | * indicating that encryption is not supported. |
| 2457 | */ |
| 2458 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2459 | |
| 2460 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2461 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2462 | * indicating that encryption is supported, but is not currently active. |
| 2463 | */ |
| 2464 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2465 | |
| 2466 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2467 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2468 | * indicating that encryption is not currently active, but is currently |
| 2469 | * being activated. This is only reported by devices that support |
| 2470 | * encryption of data and only when the storage is currently |
| 2471 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2472 | * to become encrypted will never return this value. |
| 2473 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2474 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2475 | |
| 2476 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2477 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2478 | * indicating that encryption is active. |
| 2479 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2480 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2481 | |
| 2482 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2483 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2484 | * indicating that encryption is active, but an encryption key has not |
| 2485 | * been set by the user. |
| 2486 | */ |
| 2487 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2488 | |
| 2489 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2490 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2491 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2492 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2493 | * to check encryption status. However, on some devices this activity may never return, as |
| 2494 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2495 | */ |
| 2496 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2497 | public static final String ACTION_START_ENCRYPTION |
| 2498 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2499 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2500 | * Widgets are enabled in keyguard |
| 2501 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2502 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2503 | |
| 2504 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2505 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2506 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2507 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2508 | |
| 2509 | /** |
| 2510 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2511 | */ |
| 2512 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2513 | |
| 2514 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2515 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2516 | */ |
| 2517 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2518 | |
| 2519 | /** |
| 2520 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2521 | */ |
| 2522 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2523 | |
| 2524 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2525 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2526 | * (e.g. PIN/Pattern/Password). |
| 2527 | */ |
| 2528 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2529 | |
| 2530 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2531 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2532 | */ |
| 2533 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2534 | |
| 2535 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2536 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2537 | */ |
| 2538 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2539 | |
| 2540 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2541 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2542 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2543 | * |
| 2544 | * <p>When multiple device administrators attempt to control device |
| 2545 | * encryption, the most secure, supported setting will always be |
| 2546 | * used. If any device administrator requests device encryption, |
| 2547 | * it will be enabled; Conversely, if a device administrator |
| 2548 | * attempts to disable device encryption while another |
| 2549 | * device administrator has enabled it, the call to disable will |
| 2550 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2551 | * |
| 2552 | * <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] | 2553 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2554 | * or control the encryption of any other storage areas. |
| 2555 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2556 | * {@code true}, then the directory returned by |
| 2557 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2558 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2559 | * |
| 2560 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2561 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2562 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2563 | * also require (and check for) a pattern, PIN, or password. |
| 2564 | * |
| 2565 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2566 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2567 | * @return the new request status (for all active admins) - will be one of |
| 2568 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2569 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2570 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2571 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2572 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2573 | if (mService != null) { |
| 2574 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2575 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2576 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2577 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2581 | } |
| 2582 | |
| 2583 | /** |
| 2584 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2585 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2586 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2587 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2588 | * this will return the requested encryption setting as an aggregate of all active |
| 2589 | * administrators. |
| 2590 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2591 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2592 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2593 | if (mService != null) { |
| 2594 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2595 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2596 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2597 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2598 | } |
| 2599 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2600 | return false; |
| 2601 | } |
| 2602 | |
| 2603 | /** |
| 2604 | * Called by an application that is administering the device to |
| 2605 | * determine the current encryption status of the device. |
| 2606 | * |
| 2607 | * Depending on the returned status code, the caller may proceed in different |
| 2608 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2609 | * storage system does not support encryption. If the |
| 2610 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2611 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2612 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2613 | * storage system has enabled encryption but no password is set so further action |
| 2614 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2615 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2616 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2617 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2618 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2619 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2620 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2621 | */ |
| 2622 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2623 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | /** @hide per-user version */ |
| 2627 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2628 | if (mService != null) { |
| 2629 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2630 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2631 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2632 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2633 | } |
| 2634 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2635 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2636 | } |
| 2637 | |
| 2638 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2639 | * Installs the given certificate as a user CA. |
| 2640 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2641 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2642 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2643 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2644 | * |
| 2645 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2646 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2647 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2648 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2649 | if (mService != null) { |
| 2650 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2651 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2652 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2653 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | return false; |
| 2657 | } |
| 2658 | |
| 2659 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2660 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2661 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2662 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2663 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2664 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2665 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2666 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2667 | if (mService != null) { |
| 2668 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2669 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2670 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2671 | } catch (CertificateException e) { |
| 2672 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2673 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2674 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2680 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2681 | * If a user has installed any certificates by other means than device policy these will be |
| 2682 | * included too. |
| 2683 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2684 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2685 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2686 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2687 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2688 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2689 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2690 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2691 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2692 | mService.enforceCanManageCaCerts(admin); |
| 2693 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2694 | for (String alias : certStore.userAliases()) { |
| 2695 | try { |
| 2696 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2697 | } catch (CertificateException ce) { |
| 2698 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2699 | } |
| 2700 | } |
| 2701 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2702 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2709 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2710 | * means other than device policy will also be removed, except for system CA certificates. |
| 2711 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2712 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2713 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2714 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2715 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2716 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2717 | try { |
| 2718 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2719 | .toArray(new String[0])); |
| 2720 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2721 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2722 | } |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | /** |
| 2727 | * Returns whether this certificate is installed as a trusted CA. |
| 2728 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2729 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2730 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2731 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2732 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2733 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2734 | if (mService != null) { |
| 2735 | try { |
| 2736 | mService.enforceCanManageCaCerts(admin); |
| 2737 | return getCaCertAlias(certBuffer) != null; |
| 2738 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2739 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2740 | } catch (CertificateException ce) { |
| 2741 | Log.w(TAG, "Could not parse certificate", ce); |
| 2742 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2743 | } |
| 2744 | return false; |
| 2745 | } |
| 2746 | |
| 2747 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2748 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2749 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2750 | * the certificate and use the private key, given direct user approval. |
| 2751 | * |
| 2752 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 2753 | * direct user approval. This is for security - should a certificate installer become |
| 2754 | * compromised, certificates it had already installed will be protected. |
| 2755 | * |
| 2756 | * <p>If the installer must have access to the credentials, call |
| 2757 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate, String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2758 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2759 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2760 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2761 | * @param privKey The private key to install. |
| 2762 | * @param cert The certificate to install. |
| 2763 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2764 | * with that alias already exists, it will be overwritten. |
| 2765 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2766 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2767 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2768 | @NonNull Certificate cert, @NonNull String alias) { |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2769 | return installKeyPair(admin, privKey, cert, alias, false); |
| 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2774 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2775 | * the certificate and use the private key, given direct user approval. |
| 2776 | * |
| 2777 | * <p>The caller of this API may grant itself access to the credential immediately, without user |
| 2778 | * approval. It is a best practice not to request this unless strictly necessary since it opens |
| 2779 | * up additional security vulnerabilities. |
| 2780 | * |
| 2781 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2782 | * {@code null} if calling from a delegated certificate installer. |
| 2783 | * @param privKey The private key to install. |
| 2784 | * @param cert The certificate to install. |
| 2785 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2786 | * with that alias already exists, it will be overwritten. |
| 2787 | * @param requestAccess {@code true} to request that the calling app be granted access to the |
| 2788 | * credentials immediately. Otherwise, access to the credentials will be gated by user approval. |
| 2789 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2790 | */ |
| 2791 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2792 | @NonNull Certificate cert, @NonNull String alias, boolean requestAccess) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2793 | try { |
| 2794 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2795 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2796 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2797 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2798 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2799 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2800 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2801 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2802 | } catch (CertificateException | IOException e) { |
| 2803 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2804 | } |
| 2805 | return false; |
| 2806 | } |
| 2807 | |
| 2808 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2809 | * Called by a device or profile owner, or delegated certificate installer, to remove all user |
| 2810 | * credentials installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2811 | * |
| 2812 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2813 | * {@code null} if calling from a delegated certificate installer. |
| 2814 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | 8f617d4 | 2016-03-02 19:54:04 +0000 | [diff] [blame] | 2815 | * @return {@code true} if the certificate alias no longer exists, {@code false} otherwise. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2816 | */ |
| 2817 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2818 | try { |
| 2819 | return mService.removeKeyPair(admin, alias); |
| 2820 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2821 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2822 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2826 | * @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] | 2827 | * doesn't exist. |
| 2828 | */ |
| 2829 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2830 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2831 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2832 | new ByteArrayInputStream(certBuffer)); |
| 2833 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2834 | } |
| 2835 | |
| 2836 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2837 | * 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] | 2838 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2839 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2840 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2841 | * <p> |
| 2842 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2843 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2844 | * installer. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 2845 | *<p> |
| 2846 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 2847 | * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the |
| 2848 | * supplied certificate installer package must be installed when calling this API, |
| 2849 | * otherwise an {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2850 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2851 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2852 | * @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] | 2853 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2854 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2855 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2856 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2857 | if (mService != null) { |
| 2858 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2859 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2860 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2861 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2862 | } |
| 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | /** |
| 2867 | * 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] | 2868 | * user. null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2869 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2870 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2871 | * @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] | 2872 | * if none is set. |
| 2873 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2874 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2875 | if (mService != null) { |
| 2876 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2877 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2878 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2879 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2880 | } |
| 2881 | } |
| 2882 | return null; |
| 2883 | } |
| 2884 | |
| 2885 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2886 | * Called by a device or profile owner to configure an always-on VPN connection through a |
| 2887 | * specific application for the current user. |
| 2888 | * This connection is automatically granted and persisted after a reboot. |
| 2889 | * |
| 2890 | * <p>The designated package should declare a {@link android.net.VpnService} in its |
| 2891 | * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, |
| 2892 | * otherwise the call will fail. |
| 2893 | * |
| 2894 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} |
| 2895 | * to remove an existing always-on VPN configuration. |
| 2896 | * |
| 2897 | * @return {@code true} if the package is set as always-on VPN controller; |
| 2898 | * {@code false} otherwise. |
| 2899 | */ |
| 2900 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2901 | @Nullable String vpnPackage) { |
| 2902 | if (mService != null) { |
| 2903 | try { |
| 2904 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2905 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2906 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | return false; |
| 2910 | } |
| 2911 | |
| 2912 | /** |
| 2913 | * Called by a device or profile owner to read the name of the package administering an |
| 2914 | * always-on VPN connection for the current user. |
| 2915 | * If there is no such package, or the always-on VPN is provided by the system instead |
| 2916 | * of by an application, {@code null} will be returned. |
| 2917 | * |
| 2918 | * @return Package name of VPN controller responsible for always-on VPN, |
| 2919 | * or {@code null} if none is set. |
| 2920 | */ |
| 2921 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2922 | if (mService != null) { |
| 2923 | try { |
| 2924 | return mService.getAlwaysOnVpnPackage(admin); |
| 2925 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2926 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | return null; |
| 2930 | } |
| 2931 | |
| 2932 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2933 | * 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] | 2934 | * on the device, for this user. After setting this, no applications running as this user |
| 2935 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2936 | * |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 2937 | * <p>If the caller is device owner, then the restriction will be applied to all users. |
| 2938 | * |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2939 | * <p>The calling device admin must have requested |
| 2940 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2941 | * this method; if it has not, a security exception will be thrown. |
| 2942 | * |
| 2943 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2944 | * @param disabled Whether or not the camera should be disabled. |
| 2945 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2946 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2947 | if (mService != null) { |
| 2948 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2949 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2950 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2951 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2957 | * 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] | 2958 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2959 | * @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] | 2960 | * have disabled the camera |
| 2961 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2962 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2963 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2967 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2968 | if (mService != null) { |
| 2969 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2970 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2971 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2972 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2973 | } |
| 2974 | } |
| 2975 | return false; |
| 2976 | } |
| 2977 | |
| 2978 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2979 | * Called by a device owner to request a bugreport. |
| 2980 | * |
| 2981 | * <p>There must be only one user on the device, managed by the device owner. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 2982 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2983 | * |
| 2984 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2985 | * @return {@code true} if the bugreport collection started successfully, or {@code false} |
| 2986 | * if it wasn't triggered because a previous bugreport operation is still active |
| 2987 | * (either the bugreport is still running or waiting for the user to share or decline) |
| 2988 | */ |
| 2989 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 2990 | if (mService != null) { |
| 2991 | try { |
| 2992 | return mService.requestBugreport(admin); |
| 2993 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2994 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | return false; |
| 2998 | } |
| 2999 | |
| 3000 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3001 | * Determine whether or not creating a guest user has been disabled for the device |
| 3002 | * |
| 3003 | * @hide |
| 3004 | */ |
| 3005 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3006 | // Currently guest users can always be created if multi-user is enabled |
| 3007 | // TODO introduce a policy for guest user creation |
| 3008 | return false; |
| 3009 | } |
| 3010 | |
| 3011 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3012 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3013 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3014 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3015 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3016 | * |
| 3017 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 3018 | * security exception will be thrown. |
| 3019 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 3020 | * <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] | 3021 | * blocks assist requests for all activities of the relevant user. |
| 3022 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3023 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3024 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3025 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3026 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3027 | if (mService != null) { |
| 3028 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3029 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3030 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3031 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3037 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3038 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3039 | * @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] | 3040 | * have disabled screen capture. |
| 3041 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3042 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3043 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3047 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3048 | if (mService != null) { |
| 3049 | try { |
| 3050 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3051 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3052 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3053 | } |
| 3054 | } |
| 3055 | return false; |
| 3056 | } |
| 3057 | |
| 3058 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3059 | * Called by a device owner to set whether auto time is required. If auto time is |
| 3060 | * required the user cannot set the date and time, but has to use network date and time. |
| 3061 | * |
| 3062 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 3063 | * |
| 3064 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 3065 | * be thrown. |
| 3066 | * |
| 3067 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3068 | * @param required Whether auto time is set required or not. |
| 3069 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3070 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3071 | if (mService != null) { |
| 3072 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3073 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3074 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3075 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3076 | } |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | /** |
| 3081 | * @return true if auto time is required. |
| 3082 | */ |
| 3083 | public boolean getAutoTimeRequired() { |
| 3084 | if (mService != null) { |
| 3085 | try { |
| 3086 | return mService.getAutoTimeRequired(); |
| 3087 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3088 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3089 | } |
| 3090 | } |
| 3091 | return false; |
| 3092 | } |
| 3093 | |
| 3094 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3095 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
| 3096 | * |
| 3097 | * <p>The system user is exempt from this policy - it is never ephemeral. |
| 3098 | * |
| 3099 | * <p>The calling device admin must be the device owner. If it is not, a security exception will |
| 3100 | * be thrown. |
| 3101 | * |
| 3102 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3103 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
| 3104 | * subsequently created users will be ephemeral. |
| 3105 | * @hide |
| 3106 | */ |
| 3107 | public void setForceEphemeralUsers( |
| 3108 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 3109 | if (mService != null) { |
| 3110 | try { |
| 3111 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3112 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3113 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3114 | } |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | /** |
| 3119 | * @return true if all users are created ephemeral. |
| 3120 | * @hide |
| 3121 | */ |
| 3122 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 3123 | if (mService != null) { |
| 3124 | try { |
| 3125 | return mService.getForceEphemeralUsers(admin); |
| 3126 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3127 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | return false; |
| 3131 | } |
| 3132 | |
| 3133 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3134 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3135 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3136 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3137 | * |
| 3138 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3139 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3140 | * this method; if it has not, a security exception will be thrown. |
| 3141 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3142 | * <p>Calling this from a managed profile before version |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3143 | * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. From version |
| 3144 | * {@link android.os.Build.VERSION_CODES#M} the profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3145 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3146 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there |
| 3147 | * is no separate challenge set on the managed profile. |
| 3148 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
| 3149 | * there is one, or the parent user otherwise. |
| 3150 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications |
| 3151 | * generated by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3152 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3153 | * |
| 3154 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3155 | * set on the {@link DevicePolicyManager} instance returned by |
| 3156 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the |
| 3157 | * parent profile. |
| 3158 | * |
| 3159 | * <p>Requests to disable other features on a managed profile will be ignored. |
| 3160 | * |
| 3161 | * <p>The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3162 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3163 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3164 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3165 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 3166 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3167 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3168 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 3169 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3170 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3171 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3172 | if (mService != null) { |
| 3173 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3174 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3175 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3176 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3177 | } |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3182 | * Determine whether or not features have been disabled in keyguard either by the calling |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3183 | * admin, if specified, or all admins that set retrictions on this user and its participating |
| 3184 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3185 | * |
| 3186 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3187 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3188 | * restrictions on the parent profile. |
| 3189 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3190 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3191 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3192 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3193 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3194 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3195 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3196 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3200 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3201 | if (mService != null) { |
| 3202 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3203 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3204 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3205 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3206 | } |
| 3207 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3208 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3212 | * @hide |
| 3213 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3214 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3215 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3216 | if (mService != null) { |
| 3217 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3218 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3219 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3220 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3224 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3225 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3226 | * @hide |
| 3227 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3228 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3229 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3233 | * @hide |
| 3234 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3235 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3236 | if (mService != null) { |
| 3237 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3238 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3239 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3240 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | /** |
| 3246 | * @hide |
| 3247 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3248 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3249 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3250 | if (mService != null) { |
| 3251 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3252 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3253 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3254 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3255 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3256 | } |
| 3257 | } |
| 3258 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3259 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3260 | /** |
| 3261 | * @hide |
| 3262 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3263 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3264 | if (mService != null) { |
| 3265 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3266 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3267 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3268 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3269 | } |
| 3270 | } |
| 3271 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3272 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3273 | /** |
| 3274 | * @hide |
| 3275 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3276 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3277 | if (mService != null) { |
| 3278 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3279 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3280 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3281 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3282 | } |
| 3283 | } |
| 3284 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3285 | |
| 3286 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3287 | * @hide |
| 3288 | */ |
| 3289 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3290 | if (mService != null) { |
| 3291 | try { |
| 3292 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3293 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3294 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3295 | } |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | /** |
| 3300 | * @hide |
| 3301 | */ |
| 3302 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3303 | if (mService != null) { |
| 3304 | try { |
| 3305 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3306 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3307 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3313 | * Should be called when keyguard has been dismissed. |
| 3314 | * @hide |
| 3315 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3316 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3317 | if (mService != null) { |
| 3318 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3319 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3320 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3321 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3322 | } |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * Should be called when keyguard view has been shown to the user. |
| 3328 | * @hide |
| 3329 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3330 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3331 | if (mService != null) { |
| 3332 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3333 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3334 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3335 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3336 | } |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3341 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3342 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3343 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3344 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3345 | * @return whether the package was successfully registered as the device owner. |
| 3346 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3347 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3348 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3349 | public boolean setDeviceOwner(ComponentName who) { |
| 3350 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | /** |
| 3354 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3355 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3356 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3357 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /** |
| 3361 | * @hide |
| 3362 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3363 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3364 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | /** |
| 3368 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3369 | * Sets the given package as the device owner. The package must already be installed. There |
| 3370 | * must not already be a device owner. |
| 3371 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3372 | * this method. |
| 3373 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3374 | * 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] | 3375 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3376 | * @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] | 3377 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3378 | * @return whether the package was successfully registered as the device owner. |
| 3379 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3380 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3381 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3382 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3383 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3384 | if (mService != null) { |
| 3385 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3386 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3387 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3388 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | return false; |
| 3392 | } |
| 3393 | |
| 3394 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3395 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3396 | * 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] | 3397 | * 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] | 3398 | * package is currently registered as the device owner app, pass in the package name from |
| 3399 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3400 | * 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] | 3401 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3402 | * the setup process. |
| 3403 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3404 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3405 | * @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] | 3406 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3407 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3408 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3409 | } |
| 3410 | |
| 3411 | /** |
| 3412 | * @return true if a package is registered as device owner, only when it's running on the |
| 3413 | * calling user. |
| 3414 | * |
| 3415 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3416 | * @hide |
| 3417 | */ |
| 3418 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3419 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3420 | } |
| 3421 | |
| 3422 | /** |
| 3423 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3424 | * user. |
| 3425 | * |
| 3426 | * <p>Requires the MANAGE_USERS permission. |
| 3427 | * |
| 3428 | * @hide |
| 3429 | */ |
| 3430 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3431 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3432 | } |
| 3433 | |
| 3434 | /** |
| 3435 | * @return device owner component name, only when it's running on the calling user. |
| 3436 | * |
| 3437 | * @hide |
| 3438 | */ |
| 3439 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3440 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3441 | } |
| 3442 | |
| 3443 | /** |
| 3444 | * @return device owner component name, even if it's running on a different user. |
| 3445 | * |
| 3446 | * <p>Requires the MANAGE_USERS permission. |
| 3447 | * |
| 3448 | * @hide |
| 3449 | */ |
| 3450 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3451 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3452 | } |
| 3453 | |
| 3454 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3455 | if (packageName == null) { |
| 3456 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3457 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3458 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3459 | if (deviceOwner == null) { |
| 3460 | return false; |
| 3461 | } |
| 3462 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3465 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3466 | if (mService != null) { |
| 3467 | try { |
| 3468 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3469 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3470 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3471 | } |
| 3472 | } |
| 3473 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3476 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3477 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3478 | * no device owner. |
| 3479 | * |
| 3480 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3481 | * |
| 3482 | * @hide |
| 3483 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3484 | public int getDeviceOwnerUserId() { |
| 3485 | if (mService != null) { |
| 3486 | try { |
| 3487 | return mService.getDeviceOwnerUserId(); |
| 3488 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3489 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | /** |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3496 | * Clears the current device owner. The caller must be the device owner. |
| 3497 | * |
| 3498 | * This function should be used cautiously as once it is called it cannot |
| 3499 | * be undone. The device owner can only be set as a part of device setup |
| 3500 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3501 | * |
| 3502 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3503 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3504 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3505 | if (mService != null) { |
| 3506 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3507 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3508 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3509 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3510 | } |
| 3511 | } |
| 3512 | } |
| 3513 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3514 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3515 | * Returns the device owner package name, only if it's running on the calling user. |
| 3516 | * |
| 3517 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3518 | * |
| 3519 | * @hide |
| 3520 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3521 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3522 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3523 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3524 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3528 | * @return true if the device is managed by any device owner. |
| 3529 | * |
| 3530 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3531 | * |
| 3532 | * @hide |
| 3533 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3534 | public boolean isDeviceManaged() { |
| 3535 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3536 | } |
| 3537 | |
| 3538 | /** |
| 3539 | * Returns the device owner name. Note this method *will* return the device owner |
| 3540 | * name when it's running on a different user. |
| 3541 | * |
| 3542 | * <p>Requires the MANAGE_USERS permission. |
| 3543 | * |
| 3544 | * @hide |
| 3545 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3546 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3547 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3548 | if (mService != null) { |
| 3549 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3550 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3551 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3552 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3553 | } |
| 3554 | } |
| 3555 | return null; |
| 3556 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3557 | |
| 3558 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3559 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3560 | * @deprecated Do not use |
| 3561 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3562 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3563 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3564 | @SystemApi |
| 3565 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3566 | return null; |
| 3567 | } |
| 3568 | |
| 3569 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3570 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3571 | * @deprecated Do not use |
| 3572 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3573 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3574 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3575 | @SystemApi |
| 3576 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3577 | return null; |
| 3578 | } |
| 3579 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3580 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3581 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3582 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3583 | * Sets the given component as an active admin and registers the package as the profile |
| 3584 | * owner for this user. The package must already be installed and there shouldn't be |
| 3585 | * an existing profile owner registered for this user. Also, this method must be called |
| 3586 | * before the user setup has been completed. |
| 3587 | * <p> |
| 3588 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3589 | * MANAGE_DEVICE_ADMINS permission. |
| 3590 | * @param admin The component to register as an active admin and profile owner. |
| 3591 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3592 | * @return whether the admin was successfully registered as the profile owner. |
| 3593 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3594 | * the user has already been set up. |
| 3595 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3596 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3597 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3598 | throws IllegalArgumentException { |
| 3599 | if (mService != null) { |
| 3600 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3601 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3602 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3603 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3604 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3605 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | return false; |
| 3609 | } |
| 3610 | |
| 3611 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3612 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 3613 | * be from the same package as the active profile owner for this user, otherwise a |
| 3614 | * SecurityException will be thrown. |
| 3615 | * |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3616 | * <p>This doesn't work for managed profile owners. |
| 3617 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3618 | * @param admin The component to remove as the profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3619 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3620 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3621 | if (mService != null) { |
| 3622 | try { |
| 3623 | mService.clearProfileOwner(admin); |
| 3624 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3625 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3631 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3632 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3633 | */ |
| 3634 | public boolean hasUserSetupCompleted() { |
| 3635 | if (mService != null) { |
| 3636 | try { |
| 3637 | return mService.hasUserSetupCompleted(); |
| 3638 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3639 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3640 | } |
| 3641 | } |
| 3642 | return true; |
| 3643 | } |
| 3644 | |
| 3645 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3646 | * @hide |
| 3647 | * 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] | 3648 | * already be installed. There must not already be a profile owner for this user. |
| 3649 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3650 | * this method. |
| 3651 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3652 | * - the caller is SYSTEM_UID. |
| 3653 | * - 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] | 3654 | * @param admin the component name to be registered as profile owner. |
| 3655 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3656 | * @param userHandle the userId to set the profile owner for. |
| 3657 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3658 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3659 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3660 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3661 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3662 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3663 | if (mService != null) { |
| 3664 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3665 | if (ownerName == null) { |
| 3666 | ownerName = ""; |
| 3667 | } |
| 3668 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3669 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3670 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3671 | } |
| 3672 | } |
| 3673 | return false; |
| 3674 | } |
| 3675 | |
| 3676 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3677 | * Sets the device owner information to be shown on the lock screen. |
| 3678 | * |
| 3679 | * <p>If the device owner information is {@code null} or empty then the device owner info is |
| 3680 | * 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] | 3681 | * <p>If the device owner information contains only whitespaces then the message on the lock |
| 3682 | * 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] | 3683 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 3684 | * <p>If the device owner information needs to be localized, it is the responsibility of the |
| 3685 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3686 | * and set a new version of this string accordingly. |
| 3687 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3688 | * @param admin The name of the admin component to check. |
| 3689 | * @param info Device owner information which will be displayed instead of the user |
| 3690 | * owner info. |
| 3691 | * @return Whether the device owner information has been set. |
| 3692 | */ |
| 3693 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3694 | if (mService != null) { |
| 3695 | try { |
| 3696 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3697 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3698 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | return false; |
| 3702 | } |
| 3703 | |
| 3704 | /** |
| 3705 | * @return The device owner information. If it is not set returns {@code null}. |
| 3706 | */ |
| 3707 | public String getDeviceOwnerLockScreenInfo() { |
| 3708 | if (mService != null) { |
| 3709 | try { |
| 3710 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3711 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3712 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3713 | } |
| 3714 | } |
| 3715 | return null; |
| 3716 | } |
| 3717 | |
| 3718 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3719 | * Called by device or profile owners to suspend packages for this user. |
| 3720 | * |
| 3721 | * <p>A suspended package will not be able to start activities. Its notifications will |
| 3722 | * be hidden, it will not show up in recents, will not be able to show toasts or dialogs |
| 3723 | * or ring the device. |
| 3724 | * |
| 3725 | * <p>The package must already be installed. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3726 | * |
| 3727 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3728 | * @param packageNames The package names to suspend or unsuspend. |
| 3729 | * @param suspended If set to {@code true} than the packages will be suspended, if set to |
| 3730 | * {@code false} the packages will be unsuspended. |
| 3731 | * @return an array of package names for which the suspended status is not set as requested in |
| 3732 | * this method. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3733 | */ |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3734 | public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames, |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3735 | boolean suspended) { |
| 3736 | if (mService != null) { |
| 3737 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3738 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3739 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3740 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3741 | } |
| 3742 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3743 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | /** |
| 3747 | * Called by device or profile owners to determine if a package is suspended. |
| 3748 | * |
| 3749 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3750 | * @param packageName The name of the package to retrieve the suspended status of. |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 3751 | * @return {@code true} if the package is suspended or {@code false} if the package is not |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3752 | * suspended, could not be found or an error occurred. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3753 | */ |
| 3754 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3755 | if (mService != null) { |
| 3756 | try { |
| 3757 | return mService.getPackageSuspended(admin, packageName); |
| 3758 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3759 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3760 | } |
| 3761 | } |
| 3762 | return false; |
| 3763 | } |
| 3764 | |
| 3765 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3766 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3767 | * be used. Only the profile owner can call this. |
| 3768 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3769 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3770 | * |
| 3771 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3772 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3773 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3774 | if (mService != null) { |
| 3775 | try { |
| 3776 | mService.setProfileEnabled(admin); |
| 3777 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3778 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3779 | } |
| 3780 | } |
| 3781 | } |
| 3782 | |
| 3783 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3784 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3785 | * 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] | 3786 | * never called by the profile or device owner, the name will be set to default values. |
| 3787 | * |
| 3788 | * @see #isProfileOwnerApp |
| 3789 | * @see #isDeviceOwnerApp |
| 3790 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3791 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3792 | * @param profileName The name of the profile. |
| 3793 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3794 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3795 | if (mService != null) { |
| 3796 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3797 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3798 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3799 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3800 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3801 | } |
| 3802 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3803 | |
| 3804 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3805 | * 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] | 3806 | * 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] | 3807 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3808 | * |
| 3809 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3810 | * @return Whether or not the package is registered as the profile owner. |
| 3811 | */ |
| 3812 | public boolean isProfileOwnerApp(String packageName) { |
| 3813 | if (mService != null) { |
| 3814 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 3815 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3816 | return profileOwner != null |
| 3817 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3818 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3819 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3820 | } |
| 3821 | } |
| 3822 | return false; |
| 3823 | } |
| 3824 | |
| 3825 | /** |
| 3826 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3827 | * @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] | 3828 | * owner has been set for that user. |
| 3829 | * @throws IllegalArgumentException if the userId is invalid. |
| 3830 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3831 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3832 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3833 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3834 | } |
| 3835 | |
| 3836 | /** |
| 3837 | * @see #getProfileOwner() |
| 3838 | * @hide |
| 3839 | */ |
| 3840 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3841 | if (mService != null) { |
| 3842 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3843 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3844 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3845 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | return null; |
| 3849 | } |
| 3850 | |
| 3851 | /** |
| 3852 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3853 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3854 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3855 | * @throws IllegalArgumentException if the userId is invalid. |
| 3856 | */ |
| 3857 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3858 | if (mService != null) { |
| 3859 | try { |
| 3860 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3861 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3862 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | return null; |
| 3866 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3867 | |
| 3868 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3869 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3870 | * @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] | 3871 | * @return the human readable name of the organisation associated with this profile owner or |
| 3872 | * null if one is not set. |
| 3873 | * @throws IllegalArgumentException if the userId is invalid. |
| 3874 | */ |
| 3875 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3876 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3877 | if (mService != null) { |
| 3878 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3879 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3880 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3881 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3882 | } |
| 3883 | } |
| 3884 | return null; |
| 3885 | } |
| 3886 | |
| 3887 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3888 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3889 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3890 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3891 | * the intent preferences are reset. |
| 3892 | * |
| 3893 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3894 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3895 | * intent handler for the filter. |
| 3896 | * |
| 3897 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3898 | * security exception will be thrown. |
| 3899 | * |
| 3900 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3901 | * @param filter The IntentFilter for which a default handler is added. |
| 3902 | * @param activity The Activity that is added as default intent handler. |
| 3903 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3904 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3905 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3906 | if (mService != null) { |
| 3907 | try { |
| 3908 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3909 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3910 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3911 | } |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | /** |
| 3916 | * 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] | 3917 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3918 | * |
| 3919 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3920 | * exception will be thrown. |
| 3921 | * |
| 3922 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3923 | * @param packageName The name of the package for which preferences are removed. |
| 3924 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3925 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3926 | String packageName) { |
| 3927 | if (mService != null) { |
| 3928 | try { |
| 3929 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3930 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3931 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3935 | |
| 3936 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3937 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 3938 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 3939 | * {@link #getApplicationRestrictions}. |
| 3940 | * <p> |
| 3941 | * This permission is persistent until it is later cleared by calling this method with a |
| 3942 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3943 | * <p> |
| 3944 | * The supplied application restriction managing package must be installed when calling this |
| 3945 | * API, otherwise an {@link IllegalArgumentException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3946 | * |
| 3947 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3948 | * @param packageName The package name which will be given access to application restrictions |
| 3949 | * APIs. If {@code null} is given the current package will be cleared. |
| 3950 | */ |
| 3951 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
| 3952 | @Nullable String packageName) { |
| 3953 | if (mService != null) { |
| 3954 | try { |
| 3955 | mService.setApplicationRestrictionsManagingPackage(admin, packageName); |
| 3956 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3957 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3958 | } |
| 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | /** |
| 3963 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 3964 | * package for the current user, or {@code null} if none is set. |
| 3965 | * |
| 3966 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3967 | * @return The package name allowed to manage application restrictions on the current user, or |
| 3968 | * {@code null} if none is set. |
| 3969 | */ |
| 3970 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 3971 | if (mService != null) { |
| 3972 | try { |
| 3973 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 3974 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3975 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3976 | } |
| 3977 | } |
| 3978 | return null; |
| 3979 | } |
| 3980 | |
| 3981 | /** |
| 3982 | * Returns {@code true} if the calling package has been granted permission via |
| 3983 | * {@link #setApplicationRestrictionsManagingPackage} to manage application |
| 3984 | * restrictions for the calling user. |
| 3985 | */ |
| 3986 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 3987 | if (mService != null) { |
| 3988 | try { |
| 3989 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 3990 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3991 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 3992 | } |
| 3993 | } |
| 3994 | return false; |
| 3995 | } |
| 3996 | |
| 3997 | /** |
| 3998 | * Sets the application restrictions for a given target application running in the calling user. |
| 3999 | * |
| 4000 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4001 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4002 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4003 | * |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 4004 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
| 4005 | * <ul> |
| 4006 | * <li>{@code boolean} |
| 4007 | * <li>{@code int} |
| 4008 | * <li>{@code String} or {@code String[]} |
| 4009 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4010 | * </ul> |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4011 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4012 | * <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] | 4013 | * the caller can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4014 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 4015 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4016 | * <p>The application restrictions are only made visible to the target application via |
| 4017 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or |
| 4018 | * device owner, and the application restrictions managing package via |
| 4019 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4020 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4021 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4022 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4023 | * @param packageName The name of the package to update restricted settings for. |
| 4024 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 4025 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4026 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4027 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4028 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4029 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4030 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4031 | Bundle settings) { |
| 4032 | if (mService != null) { |
| 4033 | try { |
| 4034 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 4035 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4036 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4037 | } |
| 4038 | } |
| 4039 | } |
| 4040 | |
| 4041 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4042 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 4043 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 4044 | * trust agents but those enabled by this function call. If flag |
| 4045 | * {@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] | 4046 | * |
| 4047 | * <p>The calling device admin must have requested |
| 4048 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4049 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4050 | * |
| 4051 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4052 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4053 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4054 | * will be strictly disabled according to the state of the |
| 4055 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4056 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 4057 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 4058 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4059 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4060 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4061 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4062 | if (mService != null) { |
| 4063 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4064 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4065 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4066 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4067 | } |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4072 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4073 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4074 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4075 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4076 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4077 | * this function returns a list of configurations for all admins that declare |
| 4078 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4079 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4080 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4081 | * 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] | 4082 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4083 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4084 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4085 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4086 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4087 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4091 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4092 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4093 | if (mService != null) { |
| 4094 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4095 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4096 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4097 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4098 | } |
| 4099 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4100 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4104 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 4105 | * 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] | 4106 | * |
| 4107 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4108 | * security exception will be thrown. |
| 4109 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4110 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4111 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 4112 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4113 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4114 | if (mService != null) { |
| 4115 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4116 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4117 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4118 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4119 | } |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4124 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4125 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4126 | * |
| 4127 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4128 | * security exception will be thrown. |
| 4129 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4130 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4131 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4132 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4133 | if (mService != null) { |
| 4134 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4135 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4136 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4137 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | return false; |
| 4141 | } |
| 4142 | |
| 4143 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4144 | * Determine whether or not caller-Id information has been disabled. |
| 4145 | * |
| 4146 | * @param userHandle The user for whom to check the caller-id permission |
| 4147 | * @hide |
| 4148 | */ |
| 4149 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4150 | if (mService != null) { |
| 4151 | try { |
| 4152 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4153 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4154 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4155 | } |
| 4156 | } |
| 4157 | return false; |
| 4158 | } |
| 4159 | |
| 4160 | /** |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4161 | * Called by a profile owner of a managed profile to set whether contacts search from |
| 4162 | * the managed profile will be shown in the parent profile, for incoming calls. |
| 4163 | * |
| 4164 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4165 | * security exception will be thrown. |
| 4166 | * |
| 4167 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4168 | * @param disabled If true contacts search in the managed profile is not displayed. |
| 4169 | */ |
| 4170 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4171 | boolean disabled) { |
| 4172 | if (mService != null) { |
| 4173 | try { |
| 4174 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 4175 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4176 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4177 | } |
| 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | /** |
| 4182 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4183 | * has been disabled. |
| 4184 | * |
| 4185 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 4186 | * security exception will be thrown. |
| 4187 | * |
| 4188 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4189 | */ |
| 4190 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 4191 | if (mService != null) { |
| 4192 | try { |
| 4193 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4194 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4195 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4196 | } |
| 4197 | } |
| 4198 | return false; |
| 4199 | } |
| 4200 | |
| 4201 | |
| 4202 | /** |
| 4203 | * Determine whether or not contacts search has been disabled. |
| 4204 | * |
| 4205 | * @param userHandle The user for whom to check the contacts search permission |
| 4206 | * @hide |
| 4207 | */ |
| 4208 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4209 | if (mService != null) { |
| 4210 | try { |
| 4211 | return mService |
| 4212 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4213 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4214 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4215 | } |
| 4216 | } |
| 4217 | return false; |
| 4218 | } |
| 4219 | |
| 4220 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4221 | * 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] | 4222 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4223 | * @hide |
| 4224 | */ |
| 4225 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4226 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4227 | if (mService != null) { |
| 4228 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4229 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 4230 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4231 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4232 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4233 | } |
| 4234 | } |
| 4235 | } |
| 4236 | |
| 4237 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4238 | * 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] | 4239 | * @hide |
| 4240 | */ |
| 4241 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4242 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4243 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4244 | originalIntent); |
| 4245 | } |
| 4246 | |
| 4247 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4248 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 4249 | * devices can access enterprise contacts. |
| 4250 | * <p> |
| 4251 | * The calling device admin must be a profile owner. If it is not, a |
| 4252 | * security exception will be thrown. |
| 4253 | * <p> |
| 4254 | * This API works on managed profile only. |
| 4255 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4256 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4257 | * with. |
| 4258 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 4259 | * contacts. |
| 4260 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4261 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4262 | if (mService != null) { |
| 4263 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4264 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4265 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4266 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4267 | } |
| 4268 | } |
| 4269 | } |
| 4270 | |
| 4271 | /** |
| 4272 | * Called by a profile owner of a managed profile to determine whether or |
| 4273 | * not Bluetooth devices cannot access enterprise contacts. |
| 4274 | * <p> |
| 4275 | * The calling device admin must be a profile owner. If it is not, a |
| 4276 | * security exception will be thrown. |
| 4277 | * <p> |
| 4278 | * This API works on managed profile only. |
| 4279 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4280 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4281 | * with. |
| 4282 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4283 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4284 | if (mService != null) { |
| 4285 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4286 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4287 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4288 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4289 | } |
| 4290 | } |
| 4291 | return true; |
| 4292 | } |
| 4293 | |
| 4294 | /** |
| 4295 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4296 | * <p> |
| 4297 | * This API works on managed profile UserHandle only. |
| 4298 | * |
| 4299 | * @param userHandle The user for whom to check the caller-id permission |
| 4300 | * @hide |
| 4301 | */ |
| 4302 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4303 | if (mService != null) { |
| 4304 | try { |
| 4305 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4306 | .getIdentifier()); |
| 4307 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4308 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4309 | } |
| 4310 | } |
| 4311 | return true; |
| 4312 | } |
| 4313 | |
| 4314 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4315 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 4316 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4317 | * Only activity intents are supported. |
| 4318 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4319 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4320 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 4321 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4322 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 4323 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4324 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4325 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4326 | if (mService != null) { |
| 4327 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4328 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4329 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4330 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4331 | } |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4336 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4337 | * 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] | 4338 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4339 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4340 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4341 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4342 | if (mService != null) { |
| 4343 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4344 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4345 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4346 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4347 | } |
| 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4352 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 4353 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4354 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 4355 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4356 | * By default the user can use any accessiblity service. When zero or more packages have |
| 4357 | * 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] | 4358 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4359 | * |
| 4360 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 4361 | * can be used, calling with an empty list only allows the builtin system's services. |
| 4362 | * |
| 4363 | * <p> System accesibility services are always available to the user the list can't modify |
| 4364 | * this. |
| 4365 | * |
| 4366 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4367 | * @param packageNames List of accessibility service package names. |
| 4368 | * |
| 4369 | * @return true if setting the restriction succeeded. It fail if there is |
| 4370 | * one or more non-system accessibility services enabled, that are not in the list. |
| 4371 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4372 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4373 | List<String> packageNames) { |
| 4374 | if (mService != null) { |
| 4375 | try { |
| 4376 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4377 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4378 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4379 | } |
| 4380 | } |
| 4381 | return false; |
| 4382 | } |
| 4383 | |
| 4384 | /** |
| 4385 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 4386 | * |
| 4387 | * <p>An empty list means no accessibility services except system services are allowed. |
| 4388 | * Null means all accessibility services are allowed. |
| 4389 | * |
| 4390 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4391 | * @return List of accessiblity service package names. |
| 4392 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4393 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4394 | if (mService != null) { |
| 4395 | try { |
| 4396 | return mService.getPermittedAccessibilityServices(admin); |
| 4397 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4398 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4399 | } |
| 4400 | } |
| 4401 | return null; |
| 4402 | } |
| 4403 | |
| 4404 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4405 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4406 | * |
| 4407 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4408 | * @param packageName Accessibility service package name that needs to be checked. |
| 4409 | * @param userHandle user id the admin is running as. |
| 4410 | * @return true if the accessibility service is permitted, otherwise false. |
| 4411 | * |
| 4412 | * @hide |
| 4413 | */ |
| 4414 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4415 | @NonNull String packageName, int userHandle) { |
| 4416 | if (mService != null) { |
| 4417 | try { |
| 4418 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4419 | userHandle); |
| 4420 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4421 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4422 | } |
| 4423 | } |
| 4424 | return false; |
| 4425 | } |
| 4426 | |
| 4427 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4428 | * Returns the list of accessibility services permitted by the device or profiles |
| 4429 | * owners of this user. |
| 4430 | * |
| 4431 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4432 | * it will contain the intersection of the permitted lists for any device or profile |
| 4433 | * owners that apply to this user. It will also include any system accessibility services. |
| 4434 | * |
| 4435 | * @param userId which user to check for. |
| 4436 | * @return List of accessiblity service package names. |
| 4437 | * @hide |
| 4438 | */ |
| 4439 | @SystemApi |
| 4440 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4441 | if (mService != null) { |
| 4442 | try { |
| 4443 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4444 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4445 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4446 | } |
| 4447 | } |
| 4448 | return null; |
| 4449 | } |
| 4450 | |
| 4451 | /** |
| 4452 | * Called by a profile or device owner to set the permitted input methods services. When |
| 4453 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 4454 | * user the device owner or profile owner is an admin for. |
| 4455 | * |
| 4456 | * By default the user can use any input method. When zero or more packages have |
| 4457 | * been added, input method that are not in the list and not part of the system |
| 4458 | * can not be enabled by the user. |
| 4459 | * |
| 4460 | * This method will fail if it is called for a admin that is not for the foreground user |
| 4461 | * or a profile of the foreground user. |
| 4462 | * |
| 4463 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 4464 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 4465 | * |
| 4466 | * <p> System input methods are always available to the user this method can't modify this. |
| 4467 | * |
| 4468 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4469 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 4470 | * @return true if setting the restriction succeeded. It will fail if there are |
| 4471 | * one or more non-system input methods currently enabled that are not in |
| 4472 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4473 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4474 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4475 | if (mService != null) { |
| 4476 | try { |
| 4477 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4478 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4479 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | return false; |
| 4483 | } |
| 4484 | |
| 4485 | |
| 4486 | /** |
| 4487 | * Returns the list of permitted input methods set by this device or profile owner. |
| 4488 | * |
| 4489 | * <p>An empty list means no input methods except system input methods are allowed. |
| 4490 | * Null means all input methods are allowed. |
| 4491 | * |
| 4492 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4493 | * @return List of input method package names. |
| 4494 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4495 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4496 | if (mService != null) { |
| 4497 | try { |
| 4498 | return mService.getPermittedInputMethods(admin); |
| 4499 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4500 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | return null; |
| 4504 | } |
| 4505 | |
| 4506 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4507 | * Called by the system to check if a specific input method is disabled by admin. |
| 4508 | * |
| 4509 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4510 | * @param packageName Input method package name that needs to be checked. |
| 4511 | * @param userHandle user id the admin is running as. |
| 4512 | * @return true if the input method is permitted, otherwise false. |
| 4513 | * |
| 4514 | * @hide |
| 4515 | */ |
| 4516 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4517 | @NonNull String packageName, int userHandle) { |
| 4518 | if (mService != null) { |
| 4519 | try { |
| 4520 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4521 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4522 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4523 | } |
| 4524 | } |
| 4525 | return false; |
| 4526 | } |
| 4527 | |
| 4528 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4529 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4530 | * 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] | 4531 | * |
| 4532 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4533 | * it will contain the intersection of the permitted lists for any device or profile |
| 4534 | * owners that apply to this user. It will also include any system input methods. |
| 4535 | * |
| 4536 | * @return List of input method package names. |
| 4537 | * @hide |
| 4538 | */ |
| 4539 | @SystemApi |
| 4540 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4541 | if (mService != null) { |
| 4542 | try { |
| 4543 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4544 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4545 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4546 | } |
| 4547 | } |
| 4548 | return null; |
| 4549 | } |
| 4550 | |
| 4551 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4552 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4553 | * currently installed it. |
| 4554 | * |
| 4555 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4556 | * |
| 4557 | * @return List of package names to keep cached. |
| 4558 | * @hide |
| 4559 | */ |
| 4560 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4561 | if (mService != null) { |
| 4562 | try { |
| 4563 | return mService.getKeepUninstalledPackages(admin); |
| 4564 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4565 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4566 | } |
| 4567 | } |
| 4568 | return null; |
| 4569 | } |
| 4570 | |
| 4571 | /** |
| 4572 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4573 | * currently installed it. |
| 4574 | * |
| 4575 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4576 | * automatically pre-cached.</p> |
| 4577 | * |
| 4578 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4579 | * @param packageNames List of package names to keep cached. |
| 4580 | * @hide |
| 4581 | */ |
| 4582 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4583 | @NonNull List<String> packageNames) { |
| 4584 | if (mService != null) { |
| 4585 | try { |
| 4586 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4587 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4588 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4589 | } |
| 4590 | } |
| 4591 | } |
| 4592 | |
| 4593 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4594 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4595 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4596 | * created. If you need to persist an identifier for this user, use |
| 4597 | * {@link UserManager#getSerialNumberForUser}. |
| 4598 | * |
| 4599 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4600 | * @param name the user's name |
| 4601 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4602 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4603 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4604 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4605 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4606 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4607 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4608 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4609 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4610 | return null; |
| 4611 | } |
| 4612 | |
| 4613 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4614 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4615 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4616 | * created. If you need to persist an identifier for this user, use |
| 4617 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4618 | * immediately. |
| 4619 | * |
| 4620 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4621 | * as registered as an active admin on the new user. The profile owner package will be |
| 4622 | * installed on the new user if it already is installed on the device. |
| 4623 | * |
| 4624 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4625 | * profileOwnerComponent when onEnable is called. |
| 4626 | * |
| 4627 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4628 | * @param name the user's name |
| 4629 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4630 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4631 | * the user. |
| 4632 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4633 | * on the new user. |
| 4634 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4635 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4636 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4637 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4638 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4639 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4640 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4641 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4642 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4643 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4644 | return null; |
| 4645 | } |
| 4646 | |
| 4647 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4648 | * 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] | 4649 | */ |
| 4650 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4651 | |
| 4652 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4653 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4654 | * ephemeral. |
| 4655 | * @hide |
| 4656 | */ |
| 4657 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4658 | |
| 4659 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4660 | * Called by a device owner to create a user with the specified name and a given component of |
| 4661 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4662 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4663 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4664 | * user will not be started in the background. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4665 | * |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4666 | * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also |
| 4667 | * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and |
| 4668 | * will be registered as an active admin on the new user. The profile owner package will be |
| 4669 | * installed on the new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4670 | * |
| 4671 | * <p>If the adminExtras are not null, they will be stored on the device until the user is |
| 4672 | * started for the first time. Then the extras will be passed to the admin when |
| 4673 | * onEnable is called. |
| 4674 | * |
| 4675 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4676 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4677 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
| 4678 | * same package as admin, otherwise no user is created and an IllegalArgumentException is |
| 4679 | * thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4680 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
| 4681 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4682 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4683 | * @see UserHandle |
| 4684 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4685 | * user could not be created. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4686 | */ |
| 4687 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4688 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4689 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4690 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4691 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4692 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4693 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4694 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4698 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 4699 | * not be removed. |
| 4700 | * |
| 4701 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4702 | * @param userHandle the user to remove. |
| 4703 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 4704 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4705 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4706 | try { |
| 4707 | return mService.removeUser(admin, userHandle); |
| 4708 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4709 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4714 | * Called by a device owner to switch the specified user to the foreground. |
| 4715 | * |
| 4716 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4717 | * @param userHandle the user to switch to; null will switch to primary. |
| 4718 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 4719 | * |
| 4720 | * @see Intent#ACTION_USER_FOREGROUND |
| 4721 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4722 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4723 | try { |
| 4724 | return mService.switchUser(admin, userHandle); |
| 4725 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4726 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4731 | * Retrieves the application restrictions for a given target application running in the calling |
| 4732 | * user. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4733 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4734 | * <p>The caller must be a profile or device owner on that user, or the package allowed to |
| 4735 | * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage}; |
| 4736 | * otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4737 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4738 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4739 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4740 | * @param packageName The name of the package to fetch restricted settings of. |
| 4741 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 4742 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 4743 | * if no restrictions have been set. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4744 | * |
| 4745 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4746 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4747 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4748 | if (mService != null) { |
| 4749 | try { |
| 4750 | return mService.getApplicationRestrictions(admin, packageName); |
| 4751 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4752 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4753 | } |
| 4754 | } |
| 4755 | return null; |
| 4756 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4757 | |
| 4758 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4759 | * 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] | 4760 | * <p> |
| 4761 | * The calling device admin must be a profile or device owner; if it is not, |
| 4762 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4763 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4764 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4765 | * with. |
| 4766 | * @param key The key of the restriction. See the constants in |
| 4767 | * {@link android.os.UserManager} for the list of keys. |
| 4768 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4769 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4770 | if (mService != null) { |
| 4771 | try { |
| 4772 | mService.setUserRestriction(admin, key, true); |
| 4773 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4774 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4780 | * 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] | 4781 | * <p> |
| 4782 | * The calling device admin must be a profile or device owner; if it is not, |
| 4783 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4784 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4785 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 4786 | * with. |
| 4787 | * @param key The key of the restriction. See the constants in |
| 4788 | * {@link android.os.UserManager} for the list of keys. |
| 4789 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4790 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4791 | if (mService != null) { |
| 4792 | try { |
| 4793 | mService.setUserRestriction(admin, key, false); |
| 4794 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4795 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4796 | } |
| 4797 | } |
| 4798 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4799 | |
| 4800 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4801 | * Called by a profile or device owner to get user restrictions set with |
| 4802 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4803 | * <p> |
| 4804 | * The target user may have more restrictions set by the system or other device owner / profile |
| 4805 | * owner. To get all the user restrictions currently set, use |
| 4806 | * {@link UserManager#getUserRestrictions()}. |
| 4807 | * |
| 4808 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4809 | * @throws SecurityException if the {@code admin} is not an active admin. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4810 | */ |
| 4811 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4812 | return getUserRestrictions(admin, myUserId()); |
| 4813 | } |
| 4814 | |
| 4815 | /** @hide per-user version */ |
| 4816 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4817 | Bundle ret = null; |
| 4818 | if (mService != null) { |
| 4819 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4820 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4821 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4822 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4823 | } |
| 4824 | } |
| 4825 | return ret == null ? new Bundle() : ret; |
| 4826 | } |
| 4827 | |
| 4828 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4829 | * 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] | 4830 | * is unavailable for use, but the data and actual package file remain. |
| 4831 | * |
| 4832 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4833 | * @param packageName The name of the package to hide or unhide. |
| 4834 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 4835 | * unhidden. |
| 4836 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4837 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4838 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4839 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4840 | if (mService != null) { |
| 4841 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4842 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4843 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4844 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4845 | } |
| 4846 | } |
| 4847 | return false; |
| 4848 | } |
| 4849 | |
| 4850 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4851 | * 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] | 4852 | * |
| 4853 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4854 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4855 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4856 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4857 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4858 | if (mService != null) { |
| 4859 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4860 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4861 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4862 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4863 | } |
| 4864 | } |
| 4865 | return false; |
| 4866 | } |
| 4867 | |
| 4868 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4869 | * 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] | 4870 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4871 | * |
| 4872 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4873 | * @param packageName The package to be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4874 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4875 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4876 | if (mService != null) { |
| 4877 | try { |
| 4878 | mService.enableSystemApp(admin, packageName); |
| 4879 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4880 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4881 | } |
| 4882 | } |
| 4883 | } |
| 4884 | |
| 4885 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4886 | * 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] | 4887 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4888 | * |
| 4889 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4890 | * @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] | 4891 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4892 | * @return int The number of activities that matched the intent and were installed. |
| 4893 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4894 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4895 | if (mService != null) { |
| 4896 | try { |
| 4897 | return mService.enableSystemAppWithIntent(admin, intent); |
| 4898 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4899 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4900 | } |
| 4901 | } |
| 4902 | return 0; |
| 4903 | } |
| 4904 | |
| 4905 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4906 | * Called by a device owner or profile owner to disable account management for a specific type |
| 4907 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4908 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 4909 | * <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] | 4910 | * security exception will be thrown. |
| 4911 | * |
| 4912 | * <p>When account management is disabled for an account type, adding or removing an account |
| 4913 | * of that type will not be possible. |
| 4914 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 4915 | * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
| 4916 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 4917 | * management for a specific type is disabled. |
| 4918 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4919 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4920 | * @param accountType For which account management is disabled or enabled. |
| 4921 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 4922 | * enabled (false). |
| 4923 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4924 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4925 | boolean disabled) { |
| 4926 | if (mService != null) { |
| 4927 | try { |
| 4928 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 4929 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4930 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 4931 | } |
| 4932 | } |
| 4933 | } |
| 4934 | |
| 4935 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4936 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 4937 | * |
| 4938 | * <p> Account management can be disabled/enabled by calling |
| 4939 | * {@link #setAccountManagementDisabled}. |
| 4940 | * |
| 4941 | * @return a list of account types for which account management has been disabled. |
| 4942 | * |
| 4943 | * @see #setAccountManagementDisabled |
| 4944 | */ |
| 4945 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4946 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4947 | } |
| 4948 | |
| 4949 | /** |
| 4950 | * @see #getAccountTypesWithManagementDisabled() |
| 4951 | * @hide |
| 4952 | */ |
| 4953 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4954 | if (mService != null) { |
| 4955 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 4956 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4957 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4958 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | return null; |
| 4963 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4964 | |
| 4965 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4966 | * Sets which packages may enter lock task mode. |
| 4967 | * |
| 4968 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 4969 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4970 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4971 | * 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] | 4972 | * package list results in locked tasks belonging to those packages to be finished. |
| 4973 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 4974 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4975 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4976 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4977 | * |
| 4978 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 4979 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 4980 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 4981 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4982 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4983 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4984 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4985 | if (mService != null) { |
| 4986 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 4987 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4988 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4989 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4990 | } |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 4995 | * 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] | 4996 | * |
| 4997 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 4998 | * @hide |
| 4999 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5000 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5001 | if (mService != null) { |
| 5002 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5003 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5004 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5005 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5006 | } |
| 5007 | } |
| 5008 | return null; |
| 5009 | } |
| 5010 | |
| 5011 | /** |
| 5012 | * This function lets the caller know whether the given component is allowed to start the |
| 5013 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5014 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5015 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5016 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5017 | if (mService != null) { |
| 5018 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5019 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5020 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5021 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5022 | } |
| 5023 | } |
| 5024 | return false; |
| 5025 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5026 | |
| 5027 | /** |
| 5028 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 5029 | * 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] | 5030 | * <p>The settings that can be updated with this method are: |
| 5031 | * <ul> |
| 5032 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 5033 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 5034 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5035 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5036 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5037 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 5038 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5039 | * 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] | 5040 | * 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] | 5041 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5042 | * 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] | 5043 | * </li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5044 | * </ul> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5045 | * <p>Changing the following settings has no effect as of |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5046 | * {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5047 | * <ul> |
| 5048 | * <li>{@link Settings.Global#BLUETOOTH_ON}. |
| 5049 | * Use {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5050 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
| 5051 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 5052 | * <li>{@link Settings.Global#MODE_RINGER}. |
| 5053 | * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
| 5054 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 5055 | * <li>{@link Settings.Global#WIFI_ON}. |
| 5056 | * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
| 5057 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5058 | * |
| 5059 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5060 | * @param setting The name of the setting to update. |
| 5061 | * @param value The value to update the setting to. |
| 5062 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5063 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5064 | if (mService != null) { |
| 5065 | try { |
| 5066 | mService.setGlobalSetting(admin, setting, value); |
| 5067 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5068 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5069 | } |
| 5070 | } |
| 5071 | } |
| 5072 | |
| 5073 | /** |
| 5074 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5075 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5076 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5077 | * <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] | 5078 | * <ul> |
| 5079 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5080 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5081 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5082 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5083 | * <p>A device owner can additionally update the following settings: |
| 5084 | * <ul> |
| 5085 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5086 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5087 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5088 | * @param setting The name of the setting to update. |
| 5089 | * @param value The value to update the setting to. |
| 5090 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5091 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5092 | if (mService != null) { |
| 5093 | try { |
| 5094 | mService.setSecureSetting(admin, setting, value); |
| 5095 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5096 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5097 | } |
| 5098 | } |
| 5099 | } |
| 5100 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5101 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5102 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5103 | * making permission requests of a local or remote administrator of the user. |
| 5104 | * <p/> |
| 5105 | * Only a profile owner can designate the restrictions provider. |
| 5106 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5107 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 5108 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5109 | * it removes the restrictions provider previously assigned. |
| 5110 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5111 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5112 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5113 | if (mService != null) { |
| 5114 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5115 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5116 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5117 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5118 | } |
| 5119 | } |
| 5120 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5121 | |
| 5122 | /** |
| 5123 | * Called by profile or device owners to set the master volume mute on or off. |
| 5124 | * |
| 5125 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5126 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 5127 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5128 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5129 | if (mService != null) { |
| 5130 | try { |
| 5131 | mService.setMasterVolumeMuted(admin, on); |
| 5132 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5133 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5134 | } |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | /** |
| 5139 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5140 | * |
| 5141 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5142 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 5143 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5144 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5145 | if (mService != null) { |
| 5146 | try { |
| 5147 | return mService.isMasterVolumeMuted(admin); |
| 5148 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5149 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5150 | } |
| 5151 | } |
| 5152 | return false; |
| 5153 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5154 | |
| 5155 | /** |
| 5156 | * Called by profile or device owners to change whether a user can uninstall |
| 5157 | * a package. |
| 5158 | * |
| 5159 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5160 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5161 | * @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] | 5162 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5163 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5164 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5165 | if (mService != null) { |
| 5166 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5167 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5168 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5169 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5170 | } |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5175 | * 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] | 5176 | * 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] | 5177 | * <p> |
| 5178 | * <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] | 5179 | * 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] | 5180 | * 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] | 5181 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5182 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5183 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 5184 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5185 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5186 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5187 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5188 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5189 | if (mService != null) { |
| 5190 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 5191 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5192 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5193 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5194 | } |
| 5195 | } |
| 5196 | return false; |
| 5197 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5198 | |
| 5199 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5200 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 5201 | * 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] | 5202 | * 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] | 5203 | * 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] | 5204 | * a package may have zero or more provider components, where each component |
| 5205 | * provides a different widget type. |
| 5206 | * <p> |
| 5207 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5208 | * |
| 5209 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5210 | * @param packageName The package from which widget providers are white-listed. |
| 5211 | * @return Whether the package was added. |
| 5212 | * |
| 5213 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5214 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5215 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5216 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5217 | if (mService != null) { |
| 5218 | try { |
| 5219 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 5220 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5221 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5222 | } |
| 5223 | } |
| 5224 | return false; |
| 5225 | } |
| 5226 | |
| 5227 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5228 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 5229 | * 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] | 5230 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 5231 | * android.content.ComponentName, String)}. |
| 5232 | * <p> |
| 5233 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5234 | * |
| 5235 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5236 | * @param packageName The package from which widget providers are no longer |
| 5237 | * white-listed. |
| 5238 | * @return Whether the package was removed. |
| 5239 | * |
| 5240 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5241 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5242 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5243 | public boolean removeCrossProfileWidgetProvider( |
| 5244 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5245 | if (mService != null) { |
| 5246 | try { |
| 5247 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5248 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5249 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5250 | } |
| 5251 | } |
| 5252 | return false; |
| 5253 | } |
| 5254 | |
| 5255 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5256 | * 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] | 5257 | * available in the parent profile. |
| 5258 | * |
| 5259 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5260 | * @return The white-listed package list. |
| 5261 | * |
| 5262 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5263 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5264 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5265 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5266 | if (mService != null) { |
| 5267 | try { |
| 5268 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5269 | if (providers != null) { |
| 5270 | return providers; |
| 5271 | } |
| 5272 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5273 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5274 | } |
| 5275 | } |
| 5276 | return Collections.emptyList(); |
| 5277 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5278 | |
| 5279 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5280 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5281 | * |
| 5282 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5283 | * @param icon the bitmap to set as the photo. |
| 5284 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5285 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5286 | try { |
| 5287 | mService.setUserIcon(admin, icon); |
| 5288 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5289 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5290 | } |
| 5291 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5292 | |
| 5293 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5294 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5295 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5296 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5297 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 5298 | * components in the device owner package can set system update policies and the |
| 5299 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5300 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5301 | * @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] | 5302 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5303 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5304 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5305 | if (mService != null) { |
| 5306 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5307 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5308 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5309 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5310 | } |
| 5311 | } |
| 5312 | } |
| 5313 | |
| 5314 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5315 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5316 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5317 | * @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] | 5318 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5319 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5320 | if (mService != null) { |
| 5321 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5322 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5323 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5324 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5325 | } |
| 5326 | } |
| 5327 | return null; |
| 5328 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5329 | |
| 5330 | /** |
| 5331 | * Called by a device owner to disable the keyguard altogether. |
| 5332 | * |
| 5333 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 5334 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 5335 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 5336 | * being disabled. |
| 5337 | * |
| 5338 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5339 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5340 | * |
| 5341 | * @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] | 5342 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5343 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5344 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5345 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5346 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5347 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5348 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5349 | } |
| 5350 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5351 | |
| 5352 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5353 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 5354 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5355 | * a single use device. |
| 5356 | * |
| 5357 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5358 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 5359 | * |
| 5360 | * @return {@code false} if attempting to disable the status bar failed. |
| 5361 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5362 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5363 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5364 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5365 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5366 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5367 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5368 | } |
| 5369 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5370 | |
| 5371 | /** |
| 5372 | * Callable by the system update service to notify device owners about pending updates. |
| 5373 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5374 | * permission. |
| 5375 | * |
| 5376 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5377 | * when the current pending update was first available. -1 if no update is available. |
| 5378 | * @hide |
| 5379 | */ |
| 5380 | @SystemApi |
| 5381 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5382 | if (mService != null) { |
| 5383 | try { |
| 5384 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5385 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5386 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5387 | } |
| 5388 | } |
| 5389 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5390 | |
| 5391 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5392 | * Called by profile or device owners to set the default response for future runtime permission |
| 5393 | * requests by applications. The policy can allow for normal operation which prompts the |
| 5394 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 5395 | * 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] | 5396 | * updates. When a permission is denied or granted this way, the effect is equivalent to setting |
| 5397 | * the permission grant state via {@link #setPermissionGrantState}. |
| 5398 | * |
| 5399 | * <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] | 5400 | * 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] | 5401 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5402 | * @param admin Which profile or device owner this request is associated with. |
| 5403 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 5404 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5405 | * |
| 5406 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5407 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5408 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5409 | try { |
| 5410 | mService.setPermissionPolicy(admin, policy); |
| 5411 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5412 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | /** |
| 5417 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5418 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5419 | * @param admin Which profile or device owner this request is associated with. |
| 5420 | * @return the current policy for future permission requests. |
| 5421 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5422 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5423 | try { |
| 5424 | return mService.getPermissionPolicy(admin); |
| 5425 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5426 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5427 | } |
| 5428 | } |
| 5429 | |
| 5430 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5431 | * Sets the grant state of a runtime permission for a specific application. The state |
| 5432 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 5433 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 5434 | * is denied and the user cannot manage it through the UI, and {@link |
| 5435 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 5436 | * user cannot manage it through the UI. This might affect all permissions in a |
| 5437 | * group that the runtime permission belongs to. This method can only be called |
| 5438 | * by a profile or device owner. |
| 5439 | * |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5440 | * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not |
| 5441 | * revoke the permission. It retains the previous grant, if any. |
| 5442 | * |
| 5443 | * <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] | 5444 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5445 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5446 | * @param admin Which profile or device owner this request is associated with. |
| 5447 | * @param packageName The application to grant or revoke a permission to. |
| 5448 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5449 | * @param grantState The permission grant state which is one of {@link |
| 5450 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5451 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5452 | * @return whether the permission was successfully granted or revoked. |
| 5453 | * |
| 5454 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5455 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5456 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5457 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5458 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5459 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5460 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5461 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5462 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5463 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5464 | } |
| 5465 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5466 | |
| 5467 | /** |
| 5468 | * Returns the current grant state of a runtime permission for a specific application. |
| 5469 | * |
| 5470 | * @param admin Which profile or device owner this request is associated with. |
| 5471 | * @param packageName The application to check the grant state for. |
| 5472 | * @param permission The permission to check for. |
| 5473 | * @return the current grant state specified by device policy. If the profile or device owner |
| 5474 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 5475 | * This does not indicate whether or not the permission is currently granted for the package. |
| 5476 | * |
| 5477 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 5478 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 5479 | * which indicates if the permission is currently denied or granted. |
| 5480 | * |
| 5481 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5482 | * @see PackageManager#checkPermission(String, String) |
| 5483 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5484 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5485 | String permission) { |
| 5486 | try { |
| 5487 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5488 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5489 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5490 | } |
| 5491 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5492 | |
| 5493 | /** |
| 5494 | * Returns if provisioning a managed profile or device is possible or not. |
| 5495 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5496 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 5497 | * Note that even if this method returns true, there is a slight possibility that the |
| 5498 | * provisioning will not be allowed when it is actually initiated because some event has |
| 5499 | * happened in between. |
| 5500 | * @return if provisioning a managed profile or device is possible or not. |
| 5501 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5502 | */ |
| 5503 | public boolean isProvisioningAllowed(String action) { |
| 5504 | try { |
| 5505 | return mService.isProvisioningAllowed(action); |
| 5506 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5507 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5508 | } |
| 5509 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5510 | |
| 5511 | /** |
| 5512 | * @hide |
| 5513 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5514 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5515 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5516 | * @param admin Which profile owner this request is associated with. |
| 5517 | * @return if this user is a managed profile of another user. |
| 5518 | */ |
| 5519 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5520 | try { |
| 5521 | return mService.isManagedProfile(admin); |
| 5522 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5523 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | /** |
| 5528 | * @hide |
| 5529 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5530 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5531 | * @param admin Which device owner this request is associated with. |
| 5532 | * @return if this user is a system-only user. |
| 5533 | */ |
| 5534 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5535 | try { |
| 5536 | return mService.isSystemOnlyUser(admin); |
| 5537 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5538 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5539 | } |
| 5540 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5541 | |
| 5542 | /** |
| 5543 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5544 | * |
| 5545 | * @return the MAC address of the Wi-Fi device, or null when the information is not |
| 5546 | * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5547 | * |
| 5548 | * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5549 | */ |
| 5550 | public String getWifiMacAddress() { |
| 5551 | try { |
| 5552 | return mService.getWifiMacAddress(); |
| 5553 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5554 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5555 | } |
| 5556 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5557 | |
| 5558 | /** |
| 5559 | * Called by device owner to reboot the device. |
| 5560 | */ |
| 5561 | public void reboot(@NonNull ComponentName admin) { |
| 5562 | try { |
| 5563 | mService.reboot(admin); |
| 5564 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5565 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5566 | } |
| 5567 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5568 | |
| 5569 | /** |
| 5570 | * Called by a device admin to set the short support message. This will |
| 5571 | * be displayed to the user in settings screens where funtionality has |
| 5572 | * been disabled by the admin. |
| 5573 | * |
| 5574 | * The message should be limited to a short statement such as |
| 5575 | * "This setting is disabled by your administrator. Contact someone@example.com |
| 5576 | * for support." |
| 5577 | * If the message is longer than 200 characters it may be truncated. |
| 5578 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5579 | * <p>If the short support message needs to be localized, it is the responsibility of the |
| 5580 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5581 | * and set a new version of this string accordingly. |
| 5582 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5583 | * @see #setLongSupportMessage |
| 5584 | * |
| 5585 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5586 | * @param message Short message to be displayed to the user in settings or null to |
| 5587 | * clear the existing message. |
| 5588 | */ |
| 5589 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5590 | @Nullable String message) { |
| 5591 | if (mService != null) { |
| 5592 | try { |
| 5593 | mService.setShortSupportMessage(admin, message); |
| 5594 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5595 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5596 | } |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | /** |
| 5601 | * Called by a device admin to get the short support message. |
| 5602 | * |
| 5603 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5604 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5605 | * or null if no message has been set. |
| 5606 | */ |
| 5607 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5608 | if (mService != null) { |
| 5609 | try { |
| 5610 | return mService.getShortSupportMessage(admin); |
| 5611 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5612 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5613 | } |
| 5614 | } |
| 5615 | return null; |
| 5616 | } |
| 5617 | |
| 5618 | /** |
| 5619 | * Called by a device admin to set the long support message. This will |
| 5620 | * be displayed to the user in the device administators settings screen. |
| 5621 | * |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5622 | * <p>If the long support message needs to be localized, it is the responsibility of the |
| 5623 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5624 | * and set a new version of this string accordingly. |
| 5625 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5626 | * @see #setShortSupportMessage |
| 5627 | * |
| 5628 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5629 | * @param message Long message to be displayed to the user in settings or null to |
| 5630 | * clear the existing message. |
| 5631 | */ |
| 5632 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5633 | @Nullable String message) { |
| 5634 | if (mService != null) { |
| 5635 | try { |
| 5636 | mService.setLongSupportMessage(admin, message); |
| 5637 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5638 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5639 | } |
| 5640 | } |
| 5641 | } |
| 5642 | |
| 5643 | /** |
| 5644 | * Called by a device admin to get the long support message. |
| 5645 | * |
| 5646 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5647 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5648 | * or null if no message has been set. |
| 5649 | */ |
| 5650 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5651 | if (mService != null) { |
| 5652 | try { |
| 5653 | return mService.getLongSupportMessage(admin); |
| 5654 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5655 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5656 | } |
| 5657 | } |
| 5658 | return null; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
| 5662 | * Called by the system to get the short support message. |
| 5663 | * |
| 5664 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5665 | * @param userHandle user id the admin is running as. |
| 5666 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5667 | * |
| 5668 | * @hide |
| 5669 | */ |
| 5670 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5671 | if (mService != null) { |
| 5672 | try { |
| 5673 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5674 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5675 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5676 | } |
| 5677 | } |
| 5678 | return null; |
| 5679 | } |
| 5680 | |
| 5681 | |
| 5682 | /** |
| 5683 | * Called by the system to get the long support message. |
| 5684 | * |
| 5685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5686 | * @param userHandle user id the admin is running as. |
| 5687 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5688 | * |
| 5689 | * @hide |
| 5690 | */ |
| 5691 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5692 | if (mService != null) { |
| 5693 | try { |
| 5694 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5695 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5696 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5697 | } |
| 5698 | } |
| 5699 | return null; |
| 5700 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5701 | |
| 5702 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5703 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5704 | * whose calls act on the parent profile. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5705 | * |
| 5706 | * <p> Note only some methods will work on the parent Manager. |
| 5707 | * |
| 5708 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
| 5709 | */ |
| 5710 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5711 | try { |
| 5712 | if (!mService.isManagedProfile(admin)) { |
| 5713 | throw new SecurityException("The current user does not have a parent profile."); |
| 5714 | } |
| 5715 | return new DevicePolicyManager(mContext, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5716 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5717 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5718 | } |
| 5719 | } |
| 5720 | |
| 5721 | /** |
| 5722 | * Called by device owner to control the device logging feature. Logging can only be |
| 5723 | * enabled on single user devices where the sole user is managed by the device owner. |
| 5724 | * |
| 5725 | * <p> Device logs contain various information intended for security auditing purposes. |
| 5726 | * See {@link SecurityEvent} for details. |
| 5727 | * |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5728 | * <p>There must be only one user on the device, managed by the device owner. |
| 5729 | * Otherwise a {@link SecurityException} will be thrown. |
| 5730 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5731 | * @param admin Which device owner this request is associated with. |
| 5732 | * @param enabled whether device logging should be enabled or not. |
| 5733 | * @see #retrieveDeviceLogs |
| 5734 | */ |
| 5735 | public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 5736 | try { |
| 5737 | mService.setDeviceLoggingEnabled(admin, enabled); |
| 5738 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5739 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | /** |
| 5744 | * Return whether device logging is enabled or not by the device owner. |
| 5745 | * |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5746 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 5747 | * thrown. |
| 5748 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5749 | * @param admin Which device owner this request is associated with. |
| 5750 | * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise. |
| 5751 | */ |
| 5752 | public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) { |
| 5753 | try { |
| 5754 | return mService.getDeviceLoggingEnabled(admin); |
| 5755 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5756 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5757 | } |
| 5758 | } |
| 5759 | |
| 5760 | /** |
| 5761 | * Called by device owner to retrieve all new device logging entries since the last call to |
| 5762 | * this API after device boots. |
| 5763 | * |
| 5764 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 5765 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 5766 | * |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5767 | * <p>There must be only one user on the device, managed by the device owner. |
| 5768 | * Otherwise a {@link SecurityException} will be thrown. |
| 5769 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5770 | * @param admin Which device owner this request is associated with. |
| 5771 | * @return the new batch of device logs which is a list of {@link SecurityEvent}, |
| 5772 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
| 5773 | */ |
| 5774 | public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) { |
| 5775 | try { |
| 5776 | ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin); |
| 5777 | if (list != null) { |
| 5778 | return list.getList(); |
| 5779 | } else { |
| 5780 | // Rate limit exceeded. |
| 5781 | return null; |
| 5782 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5783 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5784 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5785 | } |
| 5786 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5787 | |
| 5788 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 5789 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 5790 | * profile. |
| 5791 | * |
| 5792 | * @hide |
| 5793 | */ |
| 5794 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 5795 | mContext.checkSelfPermission( |
| 5796 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 5797 | if (!uInfo.isManagedProfile()) { |
| 5798 | throw new SecurityException("The user " + uInfo.id |
| 5799 | + " does not have a parent profile."); |
| 5800 | } |
| 5801 | return new DevicePolicyManager(mContext, true); |
| 5802 | } |
| 5803 | |
| 5804 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5805 | * Called by device owners to retrieve device logs from before the device's last reboot. |
| 5806 | * |
| 5807 | * <p> |
| 5808 | * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be |
| 5809 | * corruption-free during power cycles, due to hardware variations and limitations. As a |
| 5810 | * result, this API is provided as best-effort and the returned logs may contain corrupted data. |
| 5811 | * </strong> |
| 5812 | * |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5813 | * <p>There must be only one user on the device, managed by the device owner. |
| 5814 | * Otherwise a {@link SecurityException} will be thrown. |
| 5815 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5816 | * @param admin Which device owner this request is associated with. |
| 5817 | * @return Device logs from before the latest reboot of the system. |
| 5818 | */ |
| 5819 | public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) { |
| 5820 | try { |
| 5821 | ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin); |
| 5822 | return list.getList(); |
| 5823 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5824 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5825 | } |
| 5826 | } |
| 5827 | |
| 5828 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5829 | * Called by a profile owner of a managed profile to set the color used for customization. |
| 5830 | * This color is used as background color of the confirm credentials screen for that user. |
| 5831 | * The default color is {@link android.graphics.Color#GRAY}. |
| 5832 | * |
| 5833 | * <p>The confirm credentials screen can be created using |
| 5834 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5835 | * |
| 5836 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5837 | * @param color The 32bit representation of the color to be used. |
| 5838 | */ |
| 5839 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5840 | try { |
| 5841 | mService.setOrganizationColor(admin, color); |
| 5842 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5843 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 5848 | * @hide |
| 5849 | * |
| 5850 | * Sets the color used for customization. |
| 5851 | * |
| 5852 | * @param color The 32bit representation of the color to be used. |
| 5853 | * @param userId which user to set the color to. |
| 5854 | * @RequiresPermission(allOf = { |
| 5855 | * Manifest.permission.MANAGE_USERS, |
| 5856 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 5857 | */ |
| 5858 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 5859 | try { |
| 5860 | mService.setOrganizationColorForUser(color, userId); |
| 5861 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5862 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 5863 | } |
| 5864 | } |
| 5865 | |
| 5866 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5867 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5868 | * This color is used as background color of the confirm credentials screen for that user. |
| 5869 | * |
| 5870 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5871 | * @return The 32bit representation of the color to be used. |
| 5872 | */ |
| 5873 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 5874 | try { |
| 5875 | return mService.getOrganizationColor(admin); |
| 5876 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5877 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5878 | } |
| 5879 | } |
| 5880 | |
| 5881 | /** |
| 5882 | * @hide |
| 5883 | * Retrieve the customization color for a given user. |
| 5884 | * |
| 5885 | * @param userHandle The user id of the user we're interested in. |
| 5886 | * @return The 32bit representation of the color to be used. |
| 5887 | */ |
| 5888 | public int getOrganizationColorForUser(int userHandle) { |
| 5889 | try { |
| 5890 | return mService.getOrganizationColorForUser(userHandle); |
| 5891 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5892 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5893 | } |
| 5894 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5895 | |
| 5896 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5897 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 5898 | * management. |
| 5899 | * |
| 5900 | * <p>If the organization name needs to be localized, it is the responsibility of the |
| 5901 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5902 | * and set a new version of this string accordingly. |
| 5903 | * |
| 5904 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5905 | * @param title The organization name or {@code null} to clear a previously set name. |
| 5906 | */ |
| 5907 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 5908 | try { |
| 5909 | mService.setOrganizationName(admin, title); |
| 5910 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5911 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | /** |
| 5916 | * Called by a profile owner of a managed profile to retrieve the name of the organization |
| 5917 | * under management. |
| 5918 | * |
| 5919 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5920 | * @return The organization name or {@code null} if none is set. |
| 5921 | */ |
| 5922 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 5923 | try { |
| 5924 | return mService.getOrganizationName(admin); |
| 5925 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5926 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5927 | } |
| 5928 | } |
| 5929 | |
| 5930 | /** |
| 5931 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 5932 | * |
| 5933 | * @param userHandle The user id of the user we're interested in. |
| 5934 | * @return The organization name or {@code null} if none is set. |
| 5935 | * |
| 5936 | * @hide |
| 5937 | */ |
| 5938 | public String getOrganizationNameForUser(int userHandle) { |
| 5939 | try { |
| 5940 | return mService.getOrganizationNameForUser(userHandle); |
| 5941 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5942 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5947 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 5948 | * return {@link #STATE_USER_UNMANAGED} |
| 5949 | * @hide |
| 5950 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 5951 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5952 | @UserProvisioningState |
| 5953 | public int getUserProvisioningState() { |
| 5954 | if (mService != null) { |
| 5955 | try { |
| 5956 | return mService.getUserProvisioningState(); |
| 5957 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5958 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5959 | } |
| 5960 | } |
| 5961 | return STATE_USER_UNMANAGED; |
| 5962 | } |
| 5963 | |
| 5964 | /** |
| 5965 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 5966 | * |
| 5967 | * @param state to store |
| 5968 | * @param userHandle for user |
| 5969 | * @hide |
| 5970 | */ |
| 5971 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 5972 | if (mService != null) { |
| 5973 | try { |
| 5974 | mService.setUserProvisioningState(state, userHandle); |
| 5975 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5976 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 5977 | } |
| 5978 | } |
| 5979 | } |
| 5980 | |
| 5981 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 5982 | * @hide |
| 5983 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 5984 | * affiliated if it is managed by the same entity as the device. |
| 5985 | * |
| 5986 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 5987 | * user/profile is considered affiliated if the following conditions are both met: |
| 5988 | * <ul> |
| 5989 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 5990 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 5991 | * and a profile owner intersect, they must have come from the same source, which means that |
| 5992 | * the device owner and profile owner are controlled by the same entity.</li> |
| 5993 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 5994 | * </ul> |
| 5995 | * |
| 5996 | * @param admin Which profile or device owner this request is associated with. |
| 5997 | * @param ids A set of opaque affiliation ids. |
| 5998 | */ |
| 5999 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 6000 | try { |
| 6001 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 6002 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6003 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6004 | } |
| 6005 | } |
| 6006 | |
| 6007 | /** |
| 6008 | * @hide |
| 6009 | * Returns whether this user/profile is affiliated with the device. See |
| 6010 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 6011 | * |
| 6012 | * @return whether this user/profile is affiliated with the device. |
| 6013 | */ |
| 6014 | public boolean isAffiliatedUser() { |
| 6015 | try { |
| 6016 | return mService != null && mService.isAffiliatedUser(); |
| 6017 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6018 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6019 | } |
| 6020 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6021 | |
| 6022 | /** |
| 6023 | * @hide |
| 6024 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 6025 | * to be started |
| 6026 | * @param packageName the package to check for |
| 6027 | * @return whether the uninstall intent for {@code packageName} is pending |
| 6028 | */ |
| 6029 | public boolean isUninstallInQueue(String packageName) { |
| 6030 | try { |
| 6031 | return mService.isUninstallInQueue(packageName); |
| 6032 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6033 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | /** |
| 6038 | * @hide |
| 6039 | * @param packageName the package containing active DAs to be uninstalled |
| 6040 | */ |
| 6041 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 6042 | try { |
| 6043 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 6044 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6045 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6046 | } |
| 6047 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 6048 | } |